@@ -43,6 +43,8 @@ public async Task When_Binding_By_Programmatically_Setting_Name()
43
43
} ,
44
44
} ;
45
45
46
+ Assert . AreEqual ( null , button . Content ) ;
47
+
46
48
await UITestHelper . Load ( sp ) ;
47
49
48
50
#if UNO_HAS_ENHANCED_LIFECYCLE || WINAPPSDK
@@ -51,6 +53,72 @@ public async Task When_Binding_By_Programmatically_Setting_Name()
51
53
// Unfortunate wrong behavior on Android and iOS.
52
54
Assert . AreEqual ( null , button . Content ) ;
53
55
#endif
56
+
57
+ tb . DataContext = "Hello World Updated" ;
58
+
59
+ #if UNO_HAS_ENHANCED_LIFECYCLE || WINAPPSDK
60
+ Assert . AreEqual ( "Hello World Updated" , button . Content ) ;
61
+ #else
62
+ // Unfortunate wrong behavior on Android and iOS.
63
+ Assert . AreEqual ( null , button . Content ) ;
64
+ #endif
65
+
66
+ sp . Children . Remove ( tb ) ;
67
+
68
+ #if UNO_HAS_ENHANCED_LIFECYCLE || WINAPPSDK
69
+ Assert . AreEqual ( "Hello World Updated" , button . Content ) ;
70
+ #else
71
+ // Unfortunate wrong behavior on Android and iOS.
72
+ Assert . AreEqual ( null , button . Content ) ;
73
+ #endif
74
+
75
+ // At this point, the textBox name is was unregistered as it's removed from the visual tree.
76
+ // However, on WinUI, the binding have already solved the target for ElementName and the binding will continue to work.
77
+ tb . DataContext = "Hello World Updated 2" ;
78
+
79
+ #if UNO_HAS_ENHANCED_LIFECYCLE || WINAPPSDK
80
+ Assert . AreEqual ( "Hello World Updated 2" , button . Content ) ;
81
+ #else
82
+ // Unfortunate wrong behavior on Android and iOS.
83
+ Assert . AreEqual ( null , button . Content ) ;
84
+ #endif
85
+ }
86
+
87
+ [ TestMethod ]
88
+ public async Task When_Binding_Is_Set_After_RegisterName_And_UnregisterName ( )
89
+ {
90
+ var tb = new TextBox ( ) ;
91
+ tb . Name = "textBox" ;
92
+ tb . Text = "Text" ;
93
+ tb . DataContext = "Hello World" ;
94
+
95
+ var button = new Button ( ) ;
96
+ button . Name = "button" ;
97
+
98
+ var sp = new StackPanel ( )
99
+ {
100
+ Children =
101
+ {
102
+ tb ,
103
+ button ,
104
+ } ,
105
+ } ;
106
+
107
+ Assert . AreEqual ( null , button . Content ) ;
108
+
109
+ await UITestHelper . Load ( sp ) ;
110
+
111
+ sp . Children . Remove ( tb ) ;
112
+
113
+ // The remove call will UnregisterName for the textBox.
114
+ // The binding shouldn't be able to find the target for ElementName
115
+ button . SetBinding ( Button . ContentProperty , new Binding ( )
116
+ {
117
+ ElementName = "textBox" ,
118
+ Path = new PropertyPath ( "DataContext" )
119
+ } ) ;
120
+
121
+ Assert . AreEqual ( null , button . Content ) ;
54
122
}
55
123
56
124
[ TestMethod ]
0 commit comments