Reply to comment

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.

Reply

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