ForView.Unwrap()
In the code behind of your view, the DataContext and all of the other bound objects that you will encounter are wrapped. This occurs whether you used the ViewModelLocatorBase class, returned them from the property of a wrapped object, or wrapped them yourself with ForView.Wrap(). To access the view model within the wrapper, you need to call ForView.Unwrap().
private void ListBox_SelectionChanged( object sender, SelectionChangedEventArgs e) { foreach (object selected in e.AddedItems) { PersonViewModel viewModel = ForView.Unwrap<PersonViewModel>(selected); if (viewModel != null) viewModel.Select(); } }
You should always check the result. If you get back a null, then the wrapped object might not have been of the expected type.
Recent comments
3 years 13 weeks ago
3 years 19 weeks ago
3 years 44 weeks ago
3 years 46 weeks ago
3 years 47 weeks ago
4 years 3 days ago
4 years 3 days ago
4 years 17 weeks ago
4 years 17 weeks ago
4 years 21 weeks ago