I'm working on an MVVM app and have a view that is used to modify a number of network parameters (IP, SubnetMask, etc).
The view contains a number of text boxes bound to properties in a 'NetworkConfigViewModel':
<TextBox>
<TextBox.Text>
<Binding Path="IP" UpdateSourceTrigger="PropertyChanged"/>
</TextBox.Text>
</TextBox>
... etc
The view also contains a button called 'Save Configuration'. The button is bound to a RelayCommand in the ViewModel that takes care of saving the configuration to the remote device on request.
I would like to modify the textbox bindings to use UpdateSourceTrigger="Explicit"
so that the ViewModel only gets updated when the user explicitly clicks 'Save Configuration', rather than updating as values are modified.
I understand that I'll need to call BindingExpression.UpdateSource()
for each text box. How can I do this in an MVVM-friendly way? Adding a new RelayCommand to the ViewModel that is aware of the UI elements doesn't seem correct.