开发者

strange RaisePropertyChanged behaviour

开发者 https://www.devze.com 2023-02-03 01:05 出处:网络
I have a question regarding MVVM for WP7. In my application I have a kind of a datepicker or a calendar if you will. So after picking a day, one can choose to edit the information regarding this day b

I have a question regarding MVVM for WP7. In my application I have a kind of a datepicker or a calendar if you will. So after picking a day, one can choose to edit the information regarding this day by ckicking on it and getting to another page.

The problem is that when I change some info and click the back button the information that was altered hasn't been updating in the correspongind bindings. That's why on the navigatedto event I call a public method from my VM for that page. The sole purpose of this method (RefreshSelectedDay) is to call RaisePropertyChanged so that the binded text fields on the page get the new info. However, nothing happens. The info is actaully properties of the SelectedDay property whish is an instance of MyDay class.

  开发者_JS百科  protected override void OnNavigatedTo(NavigationEventArgs e)
    {
        ViewModel.ViewModelLocator.CalendarStatic.RefreshSelectedDay();  
    }

    /// <summary>
    /// I admit that this is by far the most stupid solution so far.
    /// RaisePropertyChanged won't work if you haven't really changed the property.
    /// That's why we set it to null and then turn it back.
    /// Used for updating the day when returning from
    /// the edit screen.
    /// </summary>
    public void RefreshSelectedDay()
    {            
        MyDay w = selectedDay;
        SelectedDay = null;
        SelectedDay = w;
    }

My solution as you can see is far from being elegant. What happens IMO is that if I just call the RaisePropertyChanged it won't propagate because it is the same variable and just one of it's properties has changed. It would be lovely if someone can explain what is happening.


"The problem is that when I change some info and click the back button the information that was altered hasn't been updating in the correspongind bindings."

That implies to me that the information that supposedly was altered, wasn't actually altered. That would also explain why youre RefreshSelectedDay doesn't seem to work either.

Are you modifying properties on SelectedDay, or creating a new instance, and that isn't getting set?

if you're modifying properties on SelectedDay, does that class properly fire property change notifications?

More code would help us debug, too.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号