tags:

views:

69

answers:

1

I have a listview, which displays a list of administrators, this list is held within a gridview, and each column has a edit button bound to the object.

Below this I have a seperate view, which is used to edit/create new administrators, what I want to do is bind the controls of this view to the Administrator selected in the Listview when the user clicks the edit button. I can get this working(ish) by populating the edit buttons tag property and casting to the relevant object in the code behind, however this doesnt follow the mvvm pattern does any one have any suggestions how I could do this using the mvvm pattern?

The view models I have are; AllAdministrators and Administrator

Thanks in advance

+1  A: 

You need a SelectedAdministrator property of type Administrator in your AllAdministrators ViewModel bound to the SelectedItem property of your ListView.

Then you should set the datacontext of the below view to SelectedAdministrator.

Now you should be able to see the SelectedItem Details shown in the view below.

I don't think clicking edit button will select the item. If it didn't, then you should select that item explicitly in the edit button's command. Else you can try getting that item's Data using edit button's DataContext.

Veer
Hi Veer, thanks for the response this what I have been trying to do, I set the edit command on the edit button and can access the object via the command parameter, however the problem comes when clicking the edit hyperlink. When the data binds to the edit hyperlink, it will be at the Administrator ViewModel level and not the AllAdministrator ViewModel so I am unable to set the selectedAdministrator.. does this make sense, am not the best at explaining my self?
jpgooner
@jpgooner: Yes! you need to get the AdministratorViewModel object from the edit command and set it as the datacontext of DetailView.
Veer
Gotcha, I suppose the best way to do this is to use create a class that inhertis from RoutedEventArgs, then set the datacontext that way, brilliant thanks for your help Veer
jpgooner