How to refresh bindings for sub-variables? #17928
Replies: 1 comment 3 replies
-
FooA and FooB need to implement INotifyPropertyChanged and raise change notifications if you want changes on them to trigger UI updates. You can't have MyViewModel raise a manual change for "Data.Foo" because that's not a property that exists. The binding system watches MyViewModel for changes to "Data" and FooB for changes to "Foo". FooB will never raise changes of Foo, and Data isn't changing so the binding systems do nothing. This is a bit different from the UWP / WPF because they automatically generators wrappers for properties of classes that didn't implement INPC for you. In Avalonia you have to do it yourself. As for not registering changes to DataContext, you'd need to provide a more complete sample to see what's causing that. |
Beta Was this translation helpful? Give feedback.
-
Given the following structures:
And the following XAML snippet:
<TextBlock Text="{Binding Data.Foo}"/>
I can only get the binding to refresh automatically when I change
DataContext.Data
specifically.When I change the
DataContext
itself, nothing happens.When I change
DataContext.Data.Foo
, nothing happens.When I change
DataContext.Data.Foo.Bar
, nothing happens.Now, I sort of get why that is (I'm only observing the
Data
property), but even when I manually callOnPropertyChanged
forData.Foo
, nothing happens still. And I can't find any way to manually refresh. And, as mentioned above, I even tried the nuclear option of giving it a whole brand newMyViewModel DataContext
instance, and that didn't refresh the value. I confirmed by stepping through the code... the values had changed, but the UI stubbornly refused to follow.So, how do I tell my UI that these sub-values changed and it needs to refresh?
Beta Was this translation helpful? Give feedback.
All reactions