, . MVVM ViewModel
public abstract class NotifyPropertyChangedBase : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
protected async void OnPropertyChanged([CallerMemberName] string propName = "")
{
await Window.Current.Dispatcher.RunAsync(CoreDispatcherPriority.High,
() =>
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propName));
});
}
}
And the whole property that Xaml binds uses oneway or twoway, and the property uses OnPropertyChanged (); And if the time of my calculus code and say thatCurrent is null
you can use
await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
//write your code
//in OnPropertyChanged use PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propName));
});
If you wrote the code in a user control or the page on which you see the code below.
await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
{
//UI code here
});
CoreDispatcherPriority can set priority, but you should not set it to High, see CoreDispatcherPriority
source
share