-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathVisualBasicPagePass2.tt
More file actions
1772 lines (1667 loc) · 89 KB
/
VisualBasicPagePass2.tt
File metadata and controls
1772 lines (1667 loc) · 89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<#@ template language="C#" inherits="VB_CodeGenerator<PageDefinition>" visibility="internal" linePragmas="false"#>
<#@ assembly name="System.Core" #>
<#@ import namespace="System.Collections.Generic" #>
<#@ import namespace="System.Linq" #>
<# foreach(var pair in Model.XamlFileFullPathAndCheckSums) #>
<# { #>
#ExternalChecksum("<#=pair.FileName#>", "<#=Model.ChecksumAlgorithmGuid#>", "<#=pair.Checksum#>")
<# } #>
'------------------------------------------------------------------------------
' <auto-generated>
' This code was generated by a tool.
'
' Changes to this file may cause incorrect behavior and will be lost if
' the code is regenerated.
' </auto-generated>
'------------------------------------------------------------------------------
Option Strict Off
Option Explicit On
Namespace <#=Globalize(Model.CodeInfo.ClassName.Namespace)#>
Partial Class <#=Model.CodeInfo.ClassName.ShortName#>
<# if (!Model.CodeInfo.IsApplication)#>
<# {#>
Implements <#=Globalize(KnownNamespaces.XamlMarkup)#>.IComponentConnector
<# if (Model.CodeInfo.HasBindingSetters) #>
<# { #>
<#=GeneratedCodeAttribute#>
<#=DebuggerNonUserCodeAttribute#>
Friend Class XamlBindingSetters
<# var bindingSetters = new HashSet<String>();#>
<# foreach (ConnectionIdElement connectionId in Model.AllConnectionIdElements)#>
<# {#>
<# foreach (BindPathStep step in connectionId.BindUniverse.BindPathSteps.Values)#>
<# {#>
<# foreach (BindAssignment bindAssignment in step.BindAssignments.Where(ba => ba.HasSetValueHelper))#>
<# {#>
<# if (!bindingSetters.Contains(bindAssignment.MemberFullName))#>
<# {#>
<# Output_Binding_SetValue_Function(bindAssignment);#>
<# bindingSetters.Add(bindAssignment.MemberFullName);#>
<# }#>
<# }#>
<# }#>
<# }#>
<# #>
End Class
<# } #>
<# if (Model.CodeInfo.IsUsingCompiledBinding) #>
<# { #>
<# Output_BindingsClasses(); #>
<# } #>
<# Output_ConnectMethod(); #>
<# Output_UnloadObjectMethod(); #>
<# Output_GetBindingConnectorMethod(); #>
<# Output_ApiInformationDeclarations(); #>
<# Output_InitializeXProperties(); #>
<# }#>
End Class
End Namespace
<#+ private void Output_InitializeXProperties() #>
<#+ { #>
<#+ if (Model.XProperties.Any()) #>
<#+ { #>
<#=GeneratedCodeAttribute#>
<#=DebuggerNonUserCodeAttribute#>
Private Sub InitializeXProperties()
<#+ foreach (xProperty xProp in Model.XProperties) #>
<#+ { #>
<#+ if (xProp.DefaultValueString != null) #>
<#+ { #>
_<#=xProp.Name#> = <#=xProp.PropertyType.GetStringToThing($"\"{xProp.DefaultValueString}\"")#>
<#+ } #>
<#+ if (xProp.DefaultValueMarkup != null) #>
<#+ { #>
_<#=xProp.Name#> = DirectCast(<#=Globalize(KnownNamespaces.XamlMarkup)#>.XamlReader.Load(<#=xProp.DefaultValueMarkup#>), <#=xProp.PropertyType.VBName()#>)
<#+ } #>
<#+ } #>
End Sub
<#+ } #>
<#+ } #>
<#+ private void Output_ConnectMethod()#>
<#+ {#>
<#=GeneratedCodeAttribute#>
<#=DebuggerNonUserCodeAttribute#>
Public Sub Connect(ByVal connectionId As Integer, ByVal target As Global.System.Object) Implements <#=Globalize(KnownNamespaces.XamlMarkup)#>.IComponentConnector.Connect
<#+ if(Model.ConnectableElements.Any()) #>
<#+ {#>
Select Case connectionId
<#+ foreach (ConnectionIdElement element in Model.ConnectableElements)#>
<#+ {#>
Case <#=element.ConnectionId#> ' <#=element.LineNumberAndXamlFile#>
<#+ FieldDefinition fieldInfo = element.FieldDefinition; #>
<#+ string objectInitName; #>
<#+ string objectName; #>
<#+ if(fieldInfo == null) #>
<#+ { #>
<#+ objectInitName = "Dim " + element.ElementCodeName + " As " + element.Type.VBName(); #>
<#+ objectName = element.ElementCodeName; #>
<#+ } #>
<#+ else #>
<#+ { #>
<#+ objectInitName = "Me." + fieldInfo.FieldName; #>
<#+ objectName = "Me." + fieldInfo.FieldName; #>
<#+ } #>
<#+ Output_PushDeprecated(element.Type.IsDeprecated()); #>
<#+ Output_ApiInformationCall_Push(element.ApiInformation, Indent.TwoTabs); #>
<#=objectInitName#> = CType(target, <#=element.Type#>)
<#+ foreach (EventAssignment ev in element.EventAssignments)#>
<#+ {#>
<#+ Output_ApiInformationCall_Push(ev.ApiInformation, Indent.TwoTabs); #>
AddHandler DirectCast(<#=objectName#>, <#=element.Type#>).<#=ev.EventName#>, AddressOf Me.<#=ev.HandlerName#>
<#+ Output_ApiInformationCall_Pop(ev.ApiInformation, Indent.TwoTabs); #>
<#+ }#>
<#+ Output_PopDeprecated(element.Type.IsDeprecated()); #>
<#+ Output_ApiInformationCall_Pop(element.ApiInformation, Indent.TwoTabs); #>
Exit Select
<#+ }#>
Case Else
Exit Select
End Select
<#+ }#>
Me._contentLoaded = true
End Sub
<#+ }#>
<#+ private void Output_UnloadObjectMethod()#>
<#+ {#>
<#+ if (Model.UnloadableFields.Count() > 0)#>
<#+ {#>
<#=GeneratedCodeAttribute#>
<#=DebuggerNonUserCodeAttribute#>
Private Sub UnloadObject(unloadableObject As <#=Globalize(KnownNamespaces.Xaml)#>.DependencyObject)
If unloadableObject IsNot Nothing Then
<#+ foreach (var element in Model.UnloadableFields) { #>
' <#=element.LineNumberAndXamlFile#>
<#+ Output_ApiInformationCall_Push(element.ApiInformation, Indent.OneTab); #>
If unloadableObject Is Me.<#=element.ElementName#> Then
Me.DisconnectUnloadedObject(<#=element.ConnectionId#>)
End If
<#+ Output_ApiInformationCall_Pop(element.ApiInformation, Indent.OneTab); #>
<#+ } #>
<#=Globalize(KnownNamespaces.XamlMarkup)#>.XamlMarkupHelper.UnloadObject(unloadableObject)
End If
End Sub
<#=GeneratedCodeAttribute#>
<#=DebuggerNonUserCodeAttribute#>
Private Sub DisconnectUnloadedObject(connectionId As Integer)
Select Case connectionId
<#+ foreach (var element in Model.DeferrableElements)#>
<#+ {#>
Case <#=element.ConnectionId#>: ' <#=element.LineNumberAndXamlFile#>
<#+ foreach (var childElem in element.Children) #>
<#+ {#>
<#+ if (childElem.HasFieldDefinition) #>
<#+ {#>
Me.DisconnectUnloadedObject(<#=childElem.ConnectionId#>)
<#+ }#>
<#+ if (childElem.HasBindAssignments || element.HasRootNamedElementStep) #>
<#+ {#>
Me.Bindings.DisconnectUnloadedObject(<#=childElem.ConnectionId#>)
<#+ }#>
<#+ }#>
<#+ if (element.HasBindAssignments || element.HasRootNamedElementStep) #>
<#+ {#>
Me.Bindings.DisconnectUnloadedObject(<#=element.ConnectionId#>)
<#+ }#>
<#+ FieldDefinition fieldInfo = element.FieldDefinition; #>
<#+ if(fieldInfo != null) #>
<#+ { #>
Me.<#=fieldInfo.FieldName#> = Nothing
<#+ } #>
Exit Select
<#+ }#>
Case Else
Throw New Global.System.ArgumentException("Invalid connectionId.")
End Select
End Sub
<#+ } #>
<#+ }#>
<#+ private void Output_GetBindingConnectorCaseBindingPropertiesSet(ConnectionIdElement element, bool isPageRoot) #>
<#+ { #>
<#+ if (element.BindUniverse.NeededForOuterScopeElement) #>
<#+ { #>
<#+ if (isPageRoot) #>
<#+ { #>
<#+ if (Model.CodeInfo.IsResourceDictionary)#>
<#+ {#>
bindings.RootWeakReference = New Global.System.WeakReference(Of <#=Globalize(KnownNamespaces.Xaml)#>.ResourceDictionary)(Me)
<#+ }#>
<#+ else#>
<#+ {#>
bindings.RootWeakReference = New Global.System.WeakReference(Of <#=Globalize(KnownNamespaces.Xaml)#>.FrameworkElement)(Me)
<#+ }#>
<#+ if (!element.BindUniverse.IsFileRoot) #>
<#+ { #>
bindings.Parent = New Global.System.WeakReference(Me.Bindings)
<#+ } #>
<#+ } #>
<#+ else #>
<#+ { #>
bindings.RootWeakReference = Me.RootWeakReference
bindings.Parent = New Global.System.WeakReference(Me)
<#+ } #>
<#+ } #>
<#+ } #>
<#+ private void Output_GetBindingConnectorCase(ConnectionIdElement element, bool isPageRoot) #>
<#+ {#>
Case <#=element.ConnectionId#>: ' <#=element.LineNumberAndXamlFile#>
<#+ Output_PushDeprecated(element.Type.IsDeprecated());#>
<#+ if (element.Type.IsDerivedFromControlTemplate())#>
<#+ {#>
Dim <#=element.ElementTemplatedParentCodeName#> As <#=element.TemplatedParentType#> = TryCast(target, <#=element.TemplatedParentType#>)
If <#=element.ElementTemplatedParentCodeName#> IsNot Nothing Then
Dim bindings As <#=element.BindUniverse.BindingsClassName#> = New <#=element.BindUniverse.BindingsClassName#>()
returnValue = bindings
bindings.SetDataRoot(<#=element.ElementTemplatedParentCodeName #>)
<#=Globalize(KnownNamespaces.XamlMarkup)#>.XamlBindingHelper.SetDataTemplateComponent(<#=element.ElementTemplatedParentCodeName#>, bindings)
<#+ PushIndent(Indent.TwoTabs); #>
<#+ Output_GetBindingConnectorCaseBindingPropertiesSet(element, isPageRoot); #>
<#+ PopIndent(); #>
End If
<#+ } else {#>
Dim <#=element.ElementCodeName#> As <#=element.Type#> = CType(target, <#=element.Type#>)
Dim bindings As <#=element.BindUniverse.BindingsClassName#> = New <#=element.BindUniverse.BindingsClassName#>()
returnValue = bindings
bindings.SetDataRoot(<#=element.IsBindingFileRoot ? "Me" : element.ElementCodeName + ".DataContext" #>)
<#+ if (element.BindUniverse.DistinctConvertersUsed.Count() > 0) #>
<#+ {#>
<#+ if (isPageRoot) #>
<#+ { #>
bindings.SetConverterLookupRoot(Me)
<#+ } #>
<#+ else #>
<#+ { #>
<#+ if (Model.CodeInfo.IsResourceDictionary)#>
<#+ {#>
Dim rootReference As <#=Globalize(KnownNamespaces.Xaml)#>.ResourceDictionary
<#+ }#>
<#+ else#>
<#+ {#>
Dim rootReference As <#=Globalize(KnownNamespaces.Xaml)#>.FrameworkElement
<#+ }#>
Me.RootWeakReference.TryGetTarget(rootReference)
bindings.SetConverterLookupRoot(rootReference)
<#+ } #>
<#+ }#>
<#+ if (element.IsBindingFileRoot)#>
<#+ { #>
Me.Bindings = bindings
If element.Type.IsDerivedFromWindow() Then
AddHandler <#=element.ElementCodeName#>.Activated, AddressOf bindings.Activated
Else
AddHandler <#=element.ElementCodeName#>.Loading, AddressOf bindings.Loading
End If
<#+ }#>
<#+ else#>
<#+ {#>
AddHandler <#=element.ElementCodeName#>.DataContextChanged, AddressOf bindings.DataContextChangedHandler
<#=Globalize(KnownNamespaces.Xaml)#>.DataTemplate.SetExtensionInstance(<#=element.ElementCodeName#>, bindings)
<#+ }#>
<#+ if (ProjectInfo.ShouldGenerateDisableXBind || !element.IsBindingFileRoot) #>
<#+ {#>
<#=Globalize(KnownNamespaces.XamlMarkup)#>.XamlBindingHelper.SetDataTemplateComponent(<#=element.ElementCodeName#>, bindings)
<#+ }#>
<#+ Output_GetBindingConnectorCaseBindingPropertiesSet(element, isPageRoot); #>
<#+ }#>
<#+ Output_PopDeprecated(element.Type.IsDeprecated()); #>
Exit Select
<#+ }#>
<#+ private void Output_GetBindingConnectorMethod()#>
<#+ {#>
<#=GeneratedCodeAttribute#>
<#=DebuggerNonUserCodeAttribute#>
Public Function GetBindingConnector(connectionId As Integer, target As Object) As <#=Globalize(KnownNamespaces.XamlMarkup)#>.IComponentConnector Implements <#=Globalize(KnownNamespaces.XamlMarkup)#>.IComponentConnector.GetBindingConnector
Dim returnValue As <#=Globalize(KnownNamespaces.XamlMarkup)#>.IComponentConnector = Nothing
<#+ if (Model.CodeInfo.BindStatus != BindStatus.None) #>
<#+ { #>
Select Case connectionId
<#+ foreach (ConnectionIdElement element in Model.AllConnectionIdElements)#>
<#+ {#>
<#+ if (element.IsBindingRoot)#>
<#+ {#>
<#+ Output_GetBindingConnectorCase(element, true); #>
<#+ }#>
<#+ }#>
End Select
<#+ } #>
Return returnValue
End Function
<#+ }#>
<#+ #>
<#+ private void Output_PushDeprecated(bool isDeprecated)#>
<#+ {#>
<#+ if (isDeprecated) #>
<#+ { #>
#Disable Warning BC40000 ' Warning on Deprecated usage
<#+ } #>
<#+ }#>
<#+ private void Output_PopDeprecated(bool isDeprecated)#>
<#+ {#>
<#+ if (isDeprecated) #>
<#+ { #>
#Enable Warning BC40000
<#+ } #>
<#+ }#>
<#+ private void Output_BindingsClasses()#>
<#+ {#>
<#+ foreach (BindUniverse bindUniverse in Model.CodeInfo.BindUniverses)#>
<#+ {#>
<#=GeneratedCodeAttribute#>
<#=DebuggerNonUserCodeAttribute#>
Private Class <#=bindUniverse.BindingsClassName#>
<#+ if (bindUniverse.NeedsIDataTemplateExtension) #>
<#+ {#>
Implements <#=Globalize(KnownNamespaces.Xaml)#>.IDataTemplateExtension
<#+ }#>
<#+ if (bindUniverse.NeedsIDataTemplateExtension || ProjectInfo.ShouldGenerateDisableXBind) #>
<#+ {#>
Implements <#=Globalize(KnownNamespaces.XamlMarkup)#>.IDataTemplateComponent
<#+ }#>
<#+ if (ProjectInfo.ShouldGenerateDisableXBind) #>
<#+ {#>
Implements <#=Globalize(KnownNamespaces.XamlMarkup)#>.IXamlBindScopeDiagnostics
<#+ }#>
<#+ if (bindUniverse.NeededForOuterScopeElement) { #>
Implements <#=Globalize(KnownNamespaces.XamlMarkup)#>.IComponentConnector
Implements I<#=Model.CodeInfo.ClassName.ShortName#>_BindingsScopeConnector
<#+ }#>
Implements <#=Globalize(KnownNamespaces.XamlMarkup)#>.IComponentConnector
Implements I<#=Model.CodeInfo.ClassName.ShortName#>_Bindings
Private dataRoot As <#=bindUniverse.DataRootType#>
<#+ if (bindUniverse.NeededForOuterScopeElement) #>
<#+ { #>
<#+ if (Model.CodeInfo.IsResourceDictionary)#>
<#+ {#>
Public Property RootWeakReference As Global.System.WeakReference(Of <#=Globalize(KnownNamespaces.Xaml)#>.ResourceDictionary)
<#+ }#>
<#+ else#>
<#+ {#>
Public Property RootWeakReference As Global.System.WeakReference(Of <#=Globalize(KnownNamespaces.Xaml)#>.FrameworkElement)
<#+ }#>
<#+ } #>
Private initialized As Boolean = False
Private Const NOT_PHASED As Integer = 1 << 31
Private Const DATA_CHANGED As Integer = 1 << 30
<#+ if (bindUniverse.DistinctConvertersUsed.Count() > 0) #>
<#+ {#>
Private localResources As <#=Globalize(KnownNamespaces.Xaml)#>.ResourceDictionary
<#+ if (!Model.CodeInfo.IsResourceDictionary)#>
<#+ {#>
Private converterLookupRoot As Global.System.WeakReference(Of <#=Globalize(KnownNamespaces.Xaml)#>.FrameworkElement)
<#+ }#>
<#+ }#>
<#+ if (bindUniverse.NeedsIDataTemplateExtension) #>
<#+ { #>
Private removedDataContextHandler As Boolean = False
<#+ } #>
' Fields for each control that has bindings.
<#+ foreach (ConnectionIdElement bindElement in bindUniverse.BoundElements)#>
<#+ {#>
<#+ if (bindElement.IsWeakRef) #>
<#+ {#>
Private <#=bindElement.ObjectCodeName#> As Global.System.WeakReference
<#+ }#>
<#+ else if (!bindElement.Type.IsDerivedFromControlTemplate()) #>
<#+ {#>
Private <#=bindElement.ObjectCodeName#> As <#=bindElement.Type#>
<#+ }#>
<#+ if (bindElement.CanBeInstantiatedLater)#>
<#+ {#>
<#+ foreach (var bindAssignment in bindElement.BindAssignments)#>
<#+ {#>
Private <#=bindAssignment.ObjectDeferredAssignmentCodeName#> As <#=bindAssignment.MemberType#>
<#+ }#>
<#+ }#>
<#+ }#>
<#+ if (bindUniverse.UnloadableBindingSourceElements.Any()) { #>
Private UnloadableBindingSourcesToUpdate As Global.System.Collections.Generic.Queue(Of Global.System.Action) = new Global.System.Collections.Generic.Queue(Of Global.System.Action)()
<#+ } #>
<#+ if (bindUniverse.ElementsWithBoundLoadAssignments.Any()) { #>
Private UnloadedElementsToUpdate As Global.System.Collections.Generic.Queue(Of Global.System.Int32) = new Global.System.Collections.Generic.Queue(Of Global.System.Int32)()
<#+ } #>
<#+ if (bindUniverse.NeedsBindingsTracking)#>
<#+ {#>
Private bindingsTracking As <#=Model.CodeInfo.ClassName.ShortName#>_obj<#=bindUniverse.RootElement.ConnectionId#>_BindingsTracking
<#+ }#>
<#+ if (bindUniverse.ElementsWithConnectCase.Where(e => e.BoundEventAssignments.Count > 0).Count() > 0)#>
<#+ {#>
' Subs for each event bindings event handler.
<#+ }#>
<#+ foreach (ConnectionIdElement element in bindUniverse.ElementsWithConnectCase)#>
<#+ {#>
<#+ foreach (BoundEventAssignment evt in element.BoundEventAssignments)#>
<#+ {#>
Private Sub <#=evt.EventHandlerCodeName#>(<#=evt.Parameters.Declaration()#>)
<#+ if (!evt.PathStep.ValueType.IsDelegate())#>
<#+ {#>
<#=evt.PathStep.CodeGen().PathExpression#>
<#+ }#>
<#+ else#>
<#+ {#>
<#=evt.PathStep.CodeGen().PathExpression#>(<#=evt.Parameters.ForCall()#>);
<#+ }#>
End Sub
<#+ }#>
<#+ }#>
' Static fields for each binding's enabled/disabled state
<#+ foreach (ConnectionIdElement bindElement in bindUniverse.ElementsWithConnectCaseInLocalScope)#>
<#+ {#>
<#+ foreach (BindAssignment ba in bindElement.BindAssignments)#>
<#+ {#>
Private Shared <#=ba.DisableFlagName#> As Boolean = False
<#+ }#>
<#+ }#>
Public Sub New()
<#+ if (bindUniverse.NeedsBindingsTracking)#>
<#+ {#>
Me.bindingsTracking = New <#=bindUniverse.BindingsClassName#>Tracking(Me)
<#+ }#>
End Sub
<#+ if (ProjectInfo.ShouldGenerateDisableXBind) #>
<#+ {#>
Public Sub Disable(lineNumber As Integer, columnNumber As Integer) Implements <#=Globalize(KnownNamespaces.XamlMarkup)#>.IXamlBindScopeDiagnostics.Disable
<#+ bool firstIfInDisable = true; #>
<#+ foreach (var element in bindUniverse.ElementsWithConnectCaseInLocalScope)#>
<#+ {#>
<#+ foreach (BindAssignment ba in element.BindAssignments)#>
<#+ {#>
<#+ if (firstIfInDisable)#>
<#+ {#>
<#+ firstIfInDisable = false; #>
If (lineNumber = <#=ba.LineNumber#> And columnNumber = <#=ba.ColumnNumber#>) Then
<#+ } else {#>
ElseIf (lineNumber = <#=ba.LineNumber#> And columnNumber = <#=ba.ColumnNumber#>) Then
<#+ }#>
<#=ba.DisableFlagName#> = True
<#+ }#>
<#+ foreach (BoundEventAssignment evt in element.BoundEventAssignments)#>
<#+ {#>
<#+ if (firstIfInDisable)#>
<#+ {#>
<#+ firstIfInDisable = false; #>
If (lineNumber = <#=evt.LineNumber#> And columnNumber = <#=evt.ColumnNumber#>) Then
<#+ } else {#>
ElseIf (lineNumber = <#=evt.LineNumber#> And columnNumber = <#=evt.ColumnNumber#>) Then
<#+ }#>
<#+ if (element.IsWeakRef)#>
<#+ {#>
If (Me.<#=element.ObjectCodeName#>.IsAlive) Then
RemoveHandler DirectCast(Me.<#=element.ObjectCodeName#>.Target, <#=element.Type#>).<#=evt.MemberName#>, AddressOf <#=evt.EventHandlerCodeName#>
End If
<#+ } else {#>
RemoveHandler Me.<#=element.ObjectCodeName#>.<#=evt.MemberName#>, AddressOf <#=evt.EventHandlerCodeName#>
<#+ }#>
<#+ }#>
<#+ }#>
<#+ if (!firstIfInDisable)#>
<#+ {#>
End If
<#+ }#>
End Sub
<#+ }#>
' IComponentConnector
Public Sub Connect(connectionId As Integer, target As Global.System.Object) Implements <#=Globalize(KnownNamespaces.XamlMarkup)#>.IComponentConnector.Connect
<#+ if (!bindUniverse.ElementsWithConnectCase.Any()) #>
<#+ { #>
Exit Sub
<#+ } #>
<#+ else #>
<#+ { #>
Select Case connectionId
<#+ foreach (ConnectionIdElement element in bindUniverse.ElementsWithConnectCase)#>
<#+ {#>
Case <#=element.ConnectionId#>: ' <#=element.LineNumberAndXamlFile#>
<#+ if (bindUniverse.BoundElements.Contains(element)) { #>
<#+ Output_ApiInformationCall_Push(element.ApiInformation, Indent.ThreeTabs); #>
<#+ if (element.IsWeakRef)#>
<#+ {#>
Me.<#=element.ObjectCodeName#> = New Global.System.WeakReference(DirectCast(target, <#=element.Type#>))
<#+ }#>
<#+ else if (element.Type.IsDerivedFromControlTemplate()) #>
<#+ {#>
Me.Update() ' Template children have been connected, initialize bindings
<#+ }#>
<#+ else#>
<#+ {#>
Me.<#=element.ObjectCodeName#> = DirectCast(target, <#=element.Type#>)
<#+ }#>
<#+ if (element.IsUsedByOtherScopes) #>
<#+ { #>
elementWeakRefs(connectionId) = New Global.System.WeakReference(target)
NotifyDependentScopes(connectionId)
<#+ } #>
<#+ foreach (BoundEventAssignment evt in element.BoundEventAssignments)#>
<#+ {#>
<#+ Output_ApiInformationCall_Push(evt.ApiInformation, Indent.ThreeTabs); #>
AddHandler DirectCast(target, <#=element.Type#>).<#=evt.MemberName#>, AddressOf <#=evt.EventHandlerCodeName#>
<#+ Output_ApiInformationCall_Pop(evt.ApiInformation, Indent.ThreeTabs); #>
<#+ }#>
<#+ if (element.CanBeInstantiatedLater && (element.HasBindAssignments || element.HasBoundEventAssignments))#>
<#+ {#>
<#+ // In Connect() we update non-load assignments first, #>
<#+ foreach (var ba in element.BindAssignments.Where(ba => !(ba is BoundLoadAssignment))) #>
<#+ { #>
<#+ PushIndent(Indent.TwoTabs); #>
<#+ Output_Binding_SetValue_Non_Function_Call(ba, "Me." + ba.ObjectDeferredAssignmentCodeName.VBName(), false); #>
<#+ PopIndent(); #>
<#+ } #>
<#+ }#>
<#+ foreach (var ba in element.BindAssignments.Where(bindAssignment => bindAssignment.IsTrackingTarget)) { #>
<#+ if (element.TwoWayBindAssignments.Any()) { #>
Me.bindingsTracking.RegisterTwoWayListener_<#=element.ConnectionId#>(<#=element.ReferenceExpression#>)
<#+ }#>
<#+ }#>
<#+ Output_ApiInformationCall_Pop(element.ApiInformation, Indent.ThreeTabs); #>
<#+ } #>
<#+ if (!element.IsBindingRoot) #>
<#+ { #>
<#+ // Queue load assignments to be updated later, because they're not available yet. #>
<#+ foreach (var childElem in element.Children.Intersect(bindUniverse.ElementsWithBoundLoadAssignments)) #>
<#+ { #>
If Not Me.UnloadedElementsToUpdate.Contains(<#=childElem.ConnectionId#>) Then
Me.UnloadedElementsToUpdate.Enqueue(<#=childElem.ConnectionId#>)
End If
<#+ } #>
<#+ } #>
<#+ if (element.CanBeInstantiatedLater && element.HasRootNamedElementStep) { #>
Me.UnloadableBindingSourcesToUpdate.Enqueue(new Global.System.Action(
Sub()
<#+ PushIndent(Indent.FourTabs); #>
<#+ Output_Custom_Update_Call("Me", element.RootNamedElementStep, element.RootNamedElementStep.CodeGen().PathExpression.VBName(), KnownStrings.NotPhased);#>
<#+ PopIndent(); #>
End Sub
))
<#+ } #>
<#+ if (element.TryGetValidationContextStep(out PropertyStep validationStep) && ProjectInfo.IsInputValidationEnabled && ProjectInfo.EnableDefaultValidationContextGeneration) #>
<#+ { #>
<#+ Output_ApiInformationCall_Push(validationStep.ApiInformation, Indent.ThreeTabs); #>
Dim validationControl As <#=Globalize(KnownNamespaces.XamlControls)#>.IInputValidationControl = DirectCast(target, <#=Globalize(KnownNamespaces.XamlControls)#>.IInputValidationControl)
validationControl.ValidationContext = New <#=Globalize(KnownNamespaces.XamlControls)#>.InputValidationContext("<#=validationStep.PropertyName #>", <#=validationStep.IsValueRequired#>)
<#+ Output_ApiInformationCall_Pop(validationStep.ApiInformation, Indent.ThreeTabs); #>
<#+ }#>
Exit Select
<#+ }#>
Case Else
Exit Select
End Select
<#+ } #>
End Sub
<#+ if (bindUniverse.NeededForOuterScopeElement) { #>
' IComponentConnector
<#=GeneratedCodeAttribute#>
<#=DebuggerNonUserCodeAttribute#>
Public Function GetBindingConnector(connectionId As Integer, target As Object) As <#=Globalize(KnownNamespaces.XamlMarkup)#>.IComponentConnector Implements <#=Globalize(KnownNamespaces.XamlMarkup)#>.IComponentConnector.GetBindingConnector
Dim returnValue As <#=Globalize(KnownNamespaces.XamlMarkup)#>.IComponentConnector = Nothing
<#+ if (bindUniverse.Children.Any()) #>
<#+ { #>
Select Case connectionId
<#+ foreach (BindUniverse childUniverse in bindUniverse.Children)#>
<#+ {#>
<#+ ConnectionIdElement element = childUniverse.RootElement;#>
<#+ if (element.IsBindingRoot)#>
<#+ {#>
<#+ PushIndent(Indent.OneTab); #>
<#+ Output_GetBindingConnectorCase(element, false); #>
<#+ PopIndent(); #>
<#+ }#>
<#+ }#>
End Select
<#+ } #>
Return returnValue
End Function
Private dependentBindings As Global.System.Collections.Generic.Dictionary(Of Integer, Global.System.Collections.Generic.List(Of Global.System.WeakReference)) = New Global.System.Collections.Generic.Dictionary(Of Integer, Global.System.Collections.Generic.List(Of Global.System.WeakReference))()
Private elementWeakRefs As Global.System.Collections.Generic.Dictionary(Of Integer, Global.System.WeakReference) = New Global.System.Collections.Generic.Dictionary(Of Integer, Global.System.WeakReference)()
' I<#=Model.CodeInfo.ClassName.ShortName#>_BindingsScopeConnector
Private _parent As Global.System.WeakReference
Property Parent() As Global.System.WeakReference Implements I<#=Model.CodeInfo.ClassName.ShortName#>_BindingsScopeConnector.Parent
Get
Return _parent
End Get
Set(value As Global.System.WeakReference)
If _parent IsNot value Then
_parent = value
RegisterDependenciesOnParents()
End If
End Set
End Property
Public Function ContainsElement(connectionId As Integer) As Boolean Implements I<#=Model.CodeInfo.ClassName.ShortName#>_BindingsScopeConnector.ContainsElement
Select Case connectionId
<#+ foreach (var element in bindUniverse.ElementsWithConnectCaseInLocalScope)#>
<#+ {#>
<#+ if (element.IsUsedByOtherScopes) #>
<#+ {#>
Case <#=element.ConnectionId#>
Return True
<#+ }#>
<#+ }#>
Case Else
Return False
End Select
End Function
Public Sub RegisterForElementConnection(connectionId As Integer, connector As <#=Globalize(KnownNamespaces.XamlMarkup)#>.IComponentConnector) Implements I<#=Model.CodeInfo.ClassName.ShortName#>_BindingsScopeConnector.RegisterForElementConnection
Dim dependentsList As Global.System.Collections.Generic.List(Of Global.System.WeakReference) = Nothing
If Not dependentBindings.TryGetValue(connectionId, dependentsList)
dependentsList = New Global.System.Collections.Generic.List(Of Global.System.WeakReference)()
dependentBindings.Add(connectionId, dependentsList)
End If
dependentsList.Add(New Global.System.WeakReference(connector))
NotifyDependentScope(connectionId, DirectCast(connector, <#=Globalize(KnownNamespaces.XamlMarkup)#>.IComponentConnector))
End Sub
Private Sub NotifyDependentScopes(connectionId As Integer)
If dependentBindings.ContainsKey(connectionId) Then
Dim dependentsList As Global.System.Collections.Generic.List(Of Global.System.WeakReference) = dependentBindings(connectionId)
For Each dependent As Global.System.WeakReference In dependentsList
If dependent.IsAlive Then
NotifyDependentScope(connectionId, DirectCast(dependent.Target, <#=Globalize(KnownNamespaces.XamlMarkup)#>.IComponentConnector))
End If
Next
End If
End Sub
Private Sub NotifyDependentScope(connectionId As Integer, connector As <#=Globalize(KnownNamespaces.XamlMarkup)#>.IComponentConnector)
If elementWeakRefs.ContainsKey(connectionId) And elementWeakRefs(connectionId).IsAlive Then
connector.Connect(connectionId, elementWeakRefs(connectionId).Target)
End If
End Sub
Private Sub RegisterDependenciesOnParents()
Dim currentParent As Global.System.WeakReference = _parent
Dim unresolvedDependencies As Global.System.Collections.Generic.List(Of Integer) = New Global.System.Collections.Generic.List(Of Integer)()
<#+ foreach (var element in bindUniverse.OuterScopeBoundElements)#>
<#+ {#>
unresolvedDependencies.Add(<#=element.ConnectionId#>)
<#+ }#>
While unresolvedDependencies.Count > 0 And Not currentParent Is Nothing And currentParent.IsAlive
Dim parentBindings As I<#=Model.CodeInfo.ClassName.ShortName#>_BindingsScopeConnector = DirectCast(currentParent.Target, I<#=Model.CodeInfo.ClassName.ShortName#>_BindingsScopeConnector)
For i As Integer= unresolvedDependencies.Count - 1 To 0 Step -1
Dim unresolvedDependency As Integer = unresolvedDependencies(i)
If parentBindings.ContainsElement(unresolvedDependency) Then
parentBindings.RegisterForElementConnection(unresolvedDependency, Me)
unresolvedDependencies.RemoveAt(i)
End If
Next
currentParent = parentBindings.Parent
End While
End Sub
<#+ } #>
<#+ if (bindUniverse.NeedsIDataTemplateExtension) #>
<#+ {#>
Public Sub DataContextChangedHandler(sender As <#=Globalize(KnownNamespaces.Xaml)#>.FrameworkElement, args As <#=Globalize(KnownNamespaces.Xaml)#>.DataContextChangedEventArgs)
If Me.SetDataRoot(args.NewValue) Then
Me.Update()
End If
End Sub
' IDataTemplateExtension
Public Function ProcessBinding(phase As UInteger) As Boolean Implements <#=Globalize(KnownNamespaces.Xaml)#>.IDataTemplateExtension.ProcessBinding
Throw New Global.System.NotImplementedException()
End Function
Public Function ProcessBindings(args As ContainerContentChangingEventArgs) As Integer Implements <#=Globalize(KnownNamespaces.Xaml)#>.IDataTemplateExtension.ProcessBindings
Dim nextPhase As Integer = -1
ProcessBindings(args.Item, args.ItemIndex, CInt(args.Phase), nextPhase)
Return nextPhase
End Function
Public Sub ResetTemplate() Implements <#=Globalize(KnownNamespaces.Xaml)#>.IDataTemplateExtension.ResetTemplate
Recycle()
End Sub
' IDataTemplateComponent
Public Sub ProcessBindings(item As Global.System.Object, itemIndex As Integer, phase As Integer, ByRef nextPhase As Integer) Implements <#=Globalize(KnownNamespaces.XamlMarkup)#>.IDataTemplateComponent.ProcessBindings
nextPhase = -1
Select Case phase
Case 0:
nextPhase = <#=bindUniverse.GetNextPhase(0)#>
Me.SetDataRoot(item)
If Not removedDataContextHandler Then
removedDataContextHandler = True
RemoveHandler <#=bindUniverse.RootElement.ReferenceExpression#>.DataContextChanged, AddressOf Me.DataContextChangedHandler
End If
Me.initialized = True
Exit Select
<#+ foreach(KeyValuePair<int, List<PhaseAssignment>> kvp in bindUniverse.PhaseAssignments.Where(kvp => kvp.Key != 0).OrderBy(kvp => kvp.Key)) #>
<#+ { #>
Case <#=kvp.Key#>:
<#+ foreach(PhaseAssignment phase in kvp.Value) #>
<#+ { #>
<#+ if (phase.ConnectionIdElement.CanBeInstantiatedLater)#>
<#+ {#>
If <#=phase.ConnectionIdElement.ReferenceExpression#> IsNot Nothing
<#+ }#>
<#=Globalize(KnownNamespaces.XamlMarkup)#>.XamlBindingHelper.ResumeRendering(<#=phase.ConnectionIdElement.ReferenceExpression#>)
<#+ if (phase.ConnectionIdElement.CanBeInstantiatedLater)#>
<#+ {#>
End If
<#+ }#>
<#+ } #>
nextPhase = <#=bindUniverse.GetNextPhase(kvp.Key)#>
Exit Select
<#+ } #>
End Select
Me.Update_(DirectCast(item, <#=bindUniverse.RootStep.ValueType#>) , 1 << phase)
End Sub
Public Sub Recycle() Implements <#=Globalize(KnownNamespaces.XamlMarkup)#>.IDataTemplateComponent.Recycle
<#+ if (bindUniverse.NeedsBindingsTracking)#>
<#+ {#>
Me.bindingsTracking.ReleaseAllListeners()
<#+ }#>
<#+ foreach(KeyValuePair<int, List<PhaseAssignment>> kvp in bindUniverse.PhaseAssignments.Where(kvp => kvp.Key != 0).OrderBy(kvp => kvp.Key)) #>
<#+ { #>
<#+ foreach(PhaseAssignment phase in kvp.Value) #>
<#+ { #>
<#+ if (phase.ConnectionIdElement.CanBeInstantiatedLater)#>
<#+ {#>
If <#=phase.ConnectionIdElement.ReferenceExpression#> IsNot Nothing
<#+ PushIndent();#>
<#+ }#>
<#=Globalize(KnownNamespaces.XamlMarkup)#>.XamlBindingHelper.SuspendRendering(<#=phase.ConnectionIdElement.ReferenceExpression#>)
<#+ if (phase.ConnectionIdElement.CanBeInstantiatedLater)#>
<#+ {#>
<#+ PopIndent();#>
End If
<#+ }#>
<#+ } #>
<#+ } #>
End Sub
<#+ } else if (bindUniverse.NeedsIDataTemplateComponent || ProjectInfo.ShouldGenerateDisableXBind){#>
' IDataTemplateComponent
Public Sub ProcessBindings(item As Global.System.Object, itemIndex As Integer, phase As Integer, ByRef nextPhase As Integer) Implements <#=Globalize(KnownNamespaces.XamlMarkup)#>.IDataTemplateComponent.ProcessBindings
nextPhase = -1
End Sub
Public Sub Recycle() Implements <#=Globalize(KnownNamespaces.XamlMarkup)#>.IDataTemplateComponent.Recycle
Exit Sub
End Sub
<#+ } #>
' I<#=Model.CodeInfo.ClassName.ShortName#>_Bindings
Public Sub Initialize() Implements I<#=Model.CodeInfo.ClassName.ShortName#>_Bindings.Initialize
If Not Me.initialized Then
Me.Update()
End If
End Sub
Public Sub Update() Implements I<#=Model.CodeInfo.ClassName.ShortName#>_Bindings.Update
<#+ if (bindUniverse.HasBindings)#>
<#+ {#>
Me.Update_<#=bindUniverse.RootStep.CodeName#>(Me.dataRoot, NOT_PHASED)
<#+ }#>
Me.initialized = True
End Sub
Public Sub StopTracking() Implements I<#=Model.CodeInfo.ClassName.ShortName#>_Bindings.StopTracking
<#+ if (bindUniverse.NeedsBindingsTracking)#>
<#+ {#>
Me.bindingsTracking.ReleaseAllListeners()
<#+ }#>
Me.initialized = False
End Sub
Public Sub DisconnectUnloadedObject(connectionId As Integer) Implements I<#=Model.CodeInfo.ClassName.ShortName#>_Bindings.DisconnectUnloadedObject
<#+ if(bindUniverse.ElementsWithDisconnectCase.Count() == 0) { #>
Throw New Global.System.ArgumentException("No unloadable elements to disconnect.")
<#+ } else { #>
Select Case connectionId
<#+ foreach (var element in bindUniverse.ElementsWithDisconnectCase)#>
<#+ {#>
Case <#=element.ConnectionId#>: ' <#=element.LineNumberAndXamlFile#>
<#+ if (bindUniverse.BoundElements.Contains(element)) { #>
<#+ Output_ApiInformationCall_Push(element.ApiInformation, Indent.OneTab); #>
If (Me.<#=element.ObjectCodeName#> IsNot Nothing) Then
<#+ foreach (BindAssignment bindAssignment in element.BindAssignments.Where(ba => ba.HasDeferredValueProxy))#>
<#+ {#>
Me.<#=bindAssignment.ObjectDeferredAssignmentCodeName#> = <#=element.GetMemberGetExpression(bindAssignment)#>
<#+ }#>
Me.<#=element.ObjectCodeName#> = Nothing
End If
<#+ foreach (var childElem in element.Children.Where(c => bindUniverse.ElementsWithDisconnectCase.Contains(c))) #>
<#+ {#>
Me.DisconnectUnloadedObject(<#=childElem.ConnectionId#>)
<#+ }#>
<#+ Output_ApiInformationCall_Pop(element.ApiInformation, Indent.OneTab); #>
<#+ } #>
<#+ if (element.HasRootNamedElementStep) { #>
Me.UnloadableBindingSourcesToUpdate.Enqueue(new Global.System.Action(
Sub()
<#+ PushIndent(Indent.FourTabs); #>
<#+ Output_Custom_Update_Call("Me", element.RootNamedElementStep, "Nothing", KnownStrings.NotPhased);#>
<#+ PopIndent(); #>
End Sub
))
<#+ } #>
Exit Select
<#+ }#>
Case Else
Throw New Global.System.ArgumentException("Invalid connectionId.")
End Select
<#+ }#>
End Sub
<#+ if (bindUniverse.ElementsWithBoundLoadAssignments.Any()) #>
<#+ { #>
Private Sub UpdateUnloadedElement(connectionId as Integer)
Select Case connectionId
<#+ foreach (var element in bindUniverse.ElementsWithBoundLoadAssignments)#>
<#+ {#>
Case <#=element.ConnectionId#>: ' <#=element.LineNumberAndXamlFile#>
<#+ Output_ApiInformationCall_Push(element.ApiInformation, Indent.OneTab); #>
<#+ // The union below is so that BoundLoadAssignments are generated first #>
<#+ foreach (var ba in element.BindAssignments.OfType<BoundLoadAssignment>()) #>
<#+ { #>
<#+ PushIndent(Indent.TwoTabs); #>
<#+ Output_Binding_SetValue_Non_Function_Call(ba, "Me." + ba.ObjectDeferredAssignmentCodeName.VBName(), false); #>
<#+ PopIndent(); #>
<#+ } #>
<#+ Output_ApiInformationCall_Pop(element.ApiInformation, Indent.OneTab); #>
Exit Select
<#+ }#>
Case Else
Throw New Global.System.ArgumentException("Invalid connectionId.")
End Select
End Sub
<#+ }#>
Public Function SetDataRoot(newDataRoot As Global.System.Object)
<#+ if (bindUniverse.NeedsBindingsTracking)#>
<#+ {#>
Me.bindingsTracking.ReleaseAllListeners()
<#+ }#>
If Not newDataRoot Is Nothing Then
Me.dataRoot = DirectCast(newDataRoot, <#=bindUniverse.DataRootType#>)
Return True
End If
Return False
End Function
<#+ if (bindUniverse.RootElement.IsBindingFileRoot)#>
<#+ {#>
Public Sub Loading(src As <#=Globalize(KnownNamespaces.Xaml)#>.FrameworkElement, data As object)
Me.Initialize()
End Sub
<#+ }#>
<#+ if (bindUniverse.DistinctConvertersUsed.Count() > 0) #>
<#+ {#>
<#+ if (Model.CodeInfo.IsResourceDictionary)#>
<#+ {#>
Public Sub SetConverterLookupRoot(resources As <#=Globalize(KnownNamespaces.Xaml)#>.ResourceDictionary)
Me.localResources = resources
End Sub
<#+ }#>
<#+ else#>
<#+ {#>
Public Sub SetConverterLookupRoot(rootElement As <#=Globalize(KnownNamespaces.Xaml)#>.FrameworkElement)
Me.converterLookupRoot = New Global.System.WeakReference(Of <#=Globalize(KnownNamespaces.Xaml)#>.FrameworkElement)(rootElement)
End Sub
<#+ }#>
Public Function LookupConverter(key As string) As <#=Globalize(KnownNamespaces.XamlData)#>.IValueConverter
<#+ if (!Model.CodeInfo.IsResourceDictionary)#>
<#+ {#>
If (Me.localResources Is Nothing)
Dim rootElement As <#=Globalize(KnownNamespaces.Xaml)#>.FrameworkElement = Nothing
Me.converterLookupRoot.TryGetTarget(rootElement)
Me.localResources = rootElement.Resources
Me.converterLookupRoot = Nothing
End If
<#+ }#>
Return DirectCast( If( Me.localResources.ContainsKey(key), Me.localResources(key), <#=Globalize(KnownNamespaces.Xaml)#>.Application.Current.Resources(key)), <#=Globalize(KnownNamespaces.XamlData)#>.IValueConverter)
End Function
<#+ }#>
<#+ if (bindUniverse.HasBindings)#>
<#+ {#>
<#+ if (bindUniverse.HasFunctionBindings)#>
<#+ {#>
<#+ Output_TryGetValueFunctions(bindUniverse);#>
<#+ Output_FunctionBindings(bindUniverse);#>
<#+ }#>
<#+ if (bindUniverse.NeedsCompleteUpdate)#>
<#+ {#>
<#+ Output_CompleteUpdate(bindUniverse);#>
<#+ }#>
' Update methods for each path node used in binding steps.
<#+ }#>
<#+ foreach (BindPathStep bindStep in bindUniverse.BindPathSteps.Values.Where(bindStep => bindStep.IsIncludedInUpdate == true))#>
<#+ {#>
Private Sub Update_<#=bindStep.CodeName#>(<#=GetUpdateParams(bindStep)#>)
<#+ if (bindStep.UpdateNeedsBindingsVariable || (bindStep is RootStep && bindUniverse.ElementRootStep != null)) { #>
Dim bindings As <#=bindUniverse.BindingsClassName#> = Me
<#+ }#>
<#+ if (bindStep.RequiresChildNotification && (bindStep is PropertyStep || bindStep is CastStep || bindStep is RootStep || bindStep is RootNamedElementStep || bindStep is ArrayIndexStep || bindStep is MapIndexStep))#>
<#+ {#>
Me.bindingsTracking.UpdateChildListeners_<#=bindStep.CodeName#>(obj)
<#+ }#>
<#+ Output_Update_Steps(bindStep.ValueType.IsNullable, "Me", bindStep.Children, true, "phase");#>
<#+ Output_Update_Steps(bindStep.ValueType.IsNullable, "Me", bindStep.Dependents, false, "phase");#>
<#+ foreach (int distinctPhase in bindStep.DistinctPhases)#>
<#+ {#>
<#+ Output_Binding_Phased_SetValue(distinctPhase, true, bindStep, false);#>
<#+ Output_Binding_Phased_SetValue(distinctPhase, false, bindStep, false);#>
<#+ }#>
<#+ if (bindStep is RootStep) { #>
<#+ Output_Update_Steps(false, "Me", bindUniverse.BindPathSteps.Values.Where(s => s.Parent is StaticRootStep), false, "phase");#>
<#+ if (bindUniverse.ElementRootStep != null) #>
<#+ { #>
<#+ Output_Update_Steps(false, "Me", bindUniverse.BindPathSteps.Values.Where(s => s.Parent == bindUniverse.ElementRootStep), false, "phase");#>
<#+ } #>
<#+ if (bindUniverse.NeedsCompleteUpdate) { #>
Me.CompleteUpdate(phase)
<#+ }#>
<#+ }#>
End Sub
<#+ }#>
<#+ // UpdateFallback generators #>
<#+ foreach (BindPathStep bindStep in bindUniverse.BindPathSteps.Values.Where(bindStep => bindStep.IsIncludedInUpdate == true))#>
<#+ {#>
<#+ if (bindStep.Parent != null && bindStep.BindStatus.HasFlag(BindStatus.HasFallbackValue))#>
<#+ {#>
Private Sub UpdateFallback_<#=bindStep.CodeName#>(phase As Integer)
<#+ foreach (BindPathStep childStep in bindStep.Children.Concat(bindStep.Dependents))#>
<#+ {#>
<#+ if (childStep.BindStatus.HasFlag(BindStatus.HasFallbackValue))#>
<#+ {#>
Me.UpdateFallback_<#=childStep.CodeName#>(phase)
<#+ }#>
<#+ }#>
<#+ foreach (int distinctPhase in bindStep.DistinctPhases) #>
<#+ {#>
<#+ Output_Binding_Phased_Fallback_SetValue(distinctPhase, true, bindStep);#>
<#+ Output_Binding_Phased_Fallback_SetValue(distinctPhase, false, bindStep);#>
<#+ }#>
End Sub
<#+ }#>
<#+ }#>
<#+ // UpdateTwoWay generators #>
<#+ foreach (var ba in bindUniverse.BindAssignments.Where(ba => ba.IsTrackingTarget)) { #>
<#+ Output_UpdateTwoWay(ba); #>
<#+ } #>
<#+ if (ProjectInfo.IsInputValidationEnabled) {#>
<#+ Output_UpdateErrors(bindUniverse); #>
<#+ } #>
<#+ if (bindUniverse.NeedsBindingsTracking)#>
<#+ {#>
<#=GeneratedCodeAttribute#>
<#=DebuggerNonUserCodeAttribute#>
Private Class <#=bindUniverse.BindingsClassName#>Tracking
Private weakRefToBindingObj As Global.System.WeakReference(Of <#=bindUniverse.BindingsClassName#>) = Nothing
Public Sub New(obj As <#=bindUniverse.BindingsClassName#>)
weakRefToBindingObj = New Global.System.WeakReference(Of <#=bindUniverse.BindingsClassName#>)(obj)