Reply to comment

ForView.Wrap()

Update Controls will fire PropertyChanged events when values change. It does so through a wrapper that it puts around objects before giving them to the view. There are three ways to get this wrapper. First, if you use the ViewModelLocatorBase class, then the ViewModel method creates the wrapper. Second, any object you return from a view model will itself be wrapped. And third, if you are setting the DataContext in code, call the ForView.Wrap() method before assigning to the DataContext.

private void UserControl_Loaded(object sender, RoutedEventArgs e)
{
    Person model = new Person();
    PersonViewModel viewModel = new PersonViewModel(model);
    this.DataContext = ForView.Wrap(viewModel);
}

The wrapper will track the dependencies in each of the properties. It will fire PropertyChanged whenever a change occurs that impacts one of the dependent properties.

Any object that you return from the property of a wrapped object will itself be wrapped. There is, however, one exception. If your object implements INotifyPropertyChanged, then the wrapper is not created. Update Controls assumes that you are handling property change notification yourself, and therefore gets out of the way.

Reply

By submitting this form, you accept the Mollom privacy policy.