开发者

wpf mvvm is it possible to have a listview with a list of objects, and below it a view containing the item selected

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开发者_Python百科(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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜