Since calling Bindings.Update()
fixed your issue, your binding expressions should be correct, but somehow the property change notification fails.
I am not going to guess what really went wrong here but to explain when you should be using Bindings.Update()
, and when you should be using INPC
+ OneWay
bindings.
Bindings.Update()
is only available for x:Bind
, unlike traditional binding, if your UI rarely needs to update with new data, you don’t have to implement INPC
with your properties, in fact, it’s actually much cheaper and more performant doing OneTime
bindings (with calling Bindings.Update()
) than implementing INPC
with OneWay
bindings.
So, the following will work with x:Bind
–
<TextBlock Text="{x:Bind MyText}" Style="{StaticResource SubheaderTextBlockStyle}" />
public string MyText { get; set; }
private void Button_Click(object sender, RoutedEventArgs e)
{
MyText = "new text!!";
Bindings.Update();
}
Once the Button is clicked, the TextBlock
will be populated with new text!!. Note here I use the default OneTime
binding (i.e. {x:Bind MyText}
) and MyText
is just a a normal CLR property.
This only works because I called Bindings.Update()
in the end, which forces OneTime
bindings to be re-initialized.
However, like I said earlier, please only consider using the above approach when your UI rarely needs to update. Most of the time this is not the case, so you will still implement INPC
and write OneWay
binding, without the need of using Bindings.Update()
at all.
solved Async Wait issues with view updation in UWP