Update UI from side Thread with 8.2.2 MVVM CommunityToolkit

80 views Asked by At

The UI does not update afterward when I modify a variable. The function who update the variable is triggered by an event which is triggered in another thread.

I tried to get back into the main thread with a dispatcher, but it doesn't work... This product since the last version with variables with properties in 8.2.2. Can you tell me how to proceed in this version ? Ty ;)

[ObservableProperty]
private SolidColorBrush ellipseFill  

private void changeColor(object? sender, FaultStateChangedEventArgs e)
{
    if (Application.Current == null) { return; }
    Application.Current.Dispatcher.BeginInvoke(new Action(() =>
    {
    ellipseFill  = e.NewFaultState ? new SolidColorBrush(Colors.Green) : new SolidColorBrush(Colors.Gray);
    Debug.WriteLine(e.NewFaultState ? "true" : "false");
}), DispatcherPriority.Normal);

}

I try a standard version without adding ObservableObject to my class. I'm implementing manually INotifyPropertyChanged or go back to 8.2.0 version of MVVM CommunityToolkit,the code is the same, just I declare the variables the old way and it's work...

Old way :

private string quantity = "";
        public string Quantity
        {
            get => quantity;
            set => SetProperty(ref quantity, value);
        }
1

There are 1 answers

1
Andrew KeepCoding On

Instead of updating the field ellipseFill, update the property EllipseFill generated by the CommunityToolkit.Mvvm.