开发者

WPF: Master - detail view with two datagrids and in MVVM

I'm trying to write a master - detail control that consists of a master datagrid and the detail datagrid. My scenario was following - I used the SelectedItem and bound it to a property in ModelView. The problem is - the SelectedItem in ViewModel is never used, so I can't get the information which item is selected in a master datagrid and cannot fetch the data for thos selection.

The code is below:

<toolkit:DataGrid ItemsSource="{Binding}"  RowDetailsVisibilityMode="VisibleWhenSelected" SelectedItem="{Binding SelectedItemHandler, Mode=TwoWay}"></toolkit:DataGrid>

And in ViewModel

private CustomerObjects _selectedItem;    
public CustomerObjects SelectedItemHandler {
                get { return _selectedItem; }
                set
                {
                         OnPropertyChanged("SelectedItem");

                }

            }

The code in SelectedItemHandler is never used. What could be the problem? Should I use another approach to create master - detai开发者_如何学JAVAl in MVVM?


You might be interested in the EventToCommand behavior provided by the MVVM Light Toolkit which will allow you to work with for instance the LostFocus (or any other for that matter) event of the Master control. Other approaches might include using a DataGrid for the Master and TextBox or TextBlock controls for the Detail.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜