tags:

views:

196

answers:

1

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.

A: 

Hi Tenfour :)!

Exactly, letting ViewModel know about View too much isn't good. I'd better update a copy of settings, and let binding do all works for me. Once user clicks 'Save Configuration' button I would propagate changes further to repository, model or whatever...

Anvaka