c# - Notify user from ViewModel and cancel navigation -


I have a view that has a list of items, a textbox and a save button. The current selected item in the text box list is bound to property T & gt; in ViewModel is now, when the user does not select an item in the list and saved
data source list is ObservableCollection & lt bound to a the Changes to the text box should be asked if they want to discard changes made by them or not. The items selected in the list should be changed only if they answer it yes.
The problem I have is:
I need to implement the inquiry for changes in Vyododal, but I do not know where, as seen, modell is not informed, when the selected items change


I came with the following method, but it does not look clear:
A list is on the Selected Selected list. I can use the EventToCommand behavior and pass the CancelEventArgs as the parameter of the command. In order, I changed the address of the object and if so, I can use Messenger to send a message, see to see. View the user will communicate confirmation and results back Dekenmodel any will return to view Moodel Cancel instead property of the event code true Sets, if the user does not want to discard their changes.
I do not see it clearly, because it separates this simple operation and smears it on three files, it is very difficult to understand.
Is there any best practice for such a scenario?

I will put a dirty check on the model class. In the example below:

  public m_dirtyFields as New Dictionary as private sub AddDirtyField (ByVal ColName String, ByVal OrigValue m_dirtyFields not as a string) if (string, string). ContainsKey (ColName) then m_dirtyFields.Add (ColName, OrigValue) end OnPropertyChanged ( "IsDirty") so as end sub Private sub RemoveDirtyField (ByVal ColName string) If m_dirtyFields.ContainsKey (ColName) then m_dirtyFields.Remove (ColName) finally OnPropertyChanged ( "IsDirty") End sub Private sub If not m_dirtyFields.ContainsKey OnAddress1Changing (ByVal value as string) ( "address 1" ) Then AddDirtyField ( "Address 1", address 1) Otherwise m_dirtyFields ( "Address 1") = value then RemoveDirtyField ( "Address 1") End If End Sub Public ReadOnly property IsDirty If _Initialized = Get False so m_dirtyFields.Clear ( ) _Initialized = Get True End if m_dirtyFields.Count & gt; 0 Return the right balance: If the final asset is exhausted then the end result   

Examples of the above property values ​​add them to a dictionary based on the similarity of the original value and in the dirty Based on the item the dictionary gives.

In your ViewModel, you can simply check MyObject.IsDirty and if this has changed, ask the user to save a message box (or not).

Additionally, while a property on a View ViewModel is advertizing the dirty property of SelectedItem. is dirty, but you can disable listbox (so that the user can not record change)

Comments

Popular posts from this blog

mysql - BLOB/TEXT column 'value' used in key specification without a key length -

c# - Using Vici cool Storage with monodroid -

python - referencing a variable in another function? -