Whistler
Whistler

Reputation: 1977

WPF MVVM Is it possible to refresh screen, so it load again?

Hi I would like to refresh/reload the View, not only the datacontext but everything. I've tried to call those 2 from controller but nothing happens:

UpdateLayout()

InvalidateVisual()

The reason for this is that I have few properties which are OneTime Mode and I would like to refresh them after the screen been saved.

Upvotes: 1

Views: 1791

Answers (1)

Zarenor
Zarenor

Reputation: 1171

OneTime properties do exactly that - They fetch their values once. If you want to trigger your updates at a particular time, then you should raise NotifyPropertyChanged for those properties at that time. If you do not want them updating every time they change, then you should not raise the event when changing the property, only when you wish the value to be updated.

However, this sounds to me like you should be using some layer of abstraction to handle this saving idea you're using, and then calculate and update those fields. If they're on a separate view (whether that's a different control, or window, or dialog, or whatever), they should not share a ViewModel (or, in ASP, controller). Instead, they should pass the information back and forth, or be synchronized to the business object you're operating on, and only update the UI when in a viewable state.

Upvotes: 1

Related Questions