File tree 1 file changed +13
-0
lines changed
1 file changed +13
-0
lines changed Original file line number Diff line number Diff line change @@ -203,6 +203,18 @@ private void MaterializeInner()
203
203
TemplatedParentScope . PushScope ( GetTemplatedParent ( ) , _fromLegacyTemplate ) ;
204
204
#endif
205
205
206
+ // Before swapping out the ElementStub, we set the inherited DC locally so that when removed from the
207
+ // visual tree, the inherited DC is kept intact. This is important in case of setting x:Load with an
208
+ // x:Bind. The binding we generate from the x:Bind will only listen to property changes while the DC
209
+ // is present. This is definitely not what happens on WinUI, but considering our implementation of
210
+ // x:Bind and ElementStub differ completely from WinUI's, this is acceptable for now.
211
+ // https://github.com/unoplatform/uno/issues/18509
212
+ if ( ( this as IDependencyObjectStoreProvider ) . Store . GetPropertyDetails ( DataContextProperty )
213
+ . CurrentHighestValuePrecedence > DependencyPropertyValuePrecedences . Local )
214
+ {
215
+ this . SetValue ( DataContextProperty , DataContext , DependencyPropertyValuePrecedences . Local ) ;
216
+ }
217
+
206
218
_content = SwapViews ( oldView : ( FrameworkElement ) this , newViewProvider : ContentBuilder ) ;
207
219
208
220
MaterializationChanged ? . Invoke ( this ) ;
@@ -226,6 +238,7 @@ private void Dematerialize()
226
238
227
239
if ( _content != null )
228
240
{
241
+ this . ClearValue ( DataContextProperty , DependencyPropertyValuePrecedences . Local ) ;
229
242
var newView = SwapViews ( oldView : ( FrameworkElement ) _content , newViewProvider : ( ) => this as View ) ;
230
243
if ( newView != null )
231
244
{
You can’t perform that action at this time.
0 commit comments