Notifying all properties of the viewmodel has changed with null or string empty

你说的曾经没有我的故事 提交于 2019-12-06 05:16:43

I see on the stack trace that there's some async code, so I'd suggest only invoking OnPropertyChanged(String.Empty) with the Dispatcher, like so:

Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
    OnPropertyChanged(string.Empty);
});

Thank's for all the answers, I was trying to fix an error that it isn't was there.

In the OnPropertyChanged(string.Empty) method raise the error because it comes with an sync context issue from the page before.

It happens when you are navigating between two page very fast and has some async calls in the OnNavigatedTo method where they aren't finished yet. The async method are awaited, but in this page was not handled that the user wait until this is finished.

Just to know that no need to apply @PedroLamas fix. Ensuring on the page before that all async calls are finished it's done.

CallerMemeberName pulls calling member name if you pass in nothing (or null) that isn’t the same string.empty

I’d fix that first.

public bool IsValid
{
    get { return isValid; }
    set
    {
        if (isValid == value)
        {
            return;
        }

        isValid = value;
        OnPropertyChanged();
    }
}

This should work. Often where I can’t use ReactiveObject or ObservableObject I tend to use this.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!