有一个DataGrid和一个TabControl的WPF MVVM主详细视图 [英] WPF MVVM Master detail view with a datagrid and a TabControl

查看:618
本文介绍了有一个DataGrid和一个TabControl的WPF MVVM主详细视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想实现在WPF MVVM主详细视图。

I am trying to implement a Master detail view in WPF MVVM.

在我的ViewModel我有原因的观察的集合。每个原因都有解决方案。

In my viewmodel I have a observable collection of "Causes". Each Cause has an observable collection of "Solutions".

我绑定一个可编辑的数据网格的原因,这是工作的罚款。但是,当用户在数据网格选择一行欲允许用户看到的TabControl其相应的解决方法。

I bound an editable Datagrid to the Causes and it is working fine. But when a user selects a row in the DataGrid I want to allow the user to see its associated solutions in the TabControl.

我应该如何去这样做?我应该创建一个属性CurrentCause在视图模型,并将其绑定到的SelectedItem。在TabControl的,我可以绑定到CurrentCause.Solutions。

How should I go about doing this? Should I create a property CurrentCause in the Viewmodel and bind it to the SelectedItem. In the TabControl can I bind to CurrentCause.Solutions.

这会不会是最佳的方法呢?请指教。谢谢!!

Will this be an optimal approach? Please advise. Thanks!!

推荐答案

您可以绑定的ItemsSource 的的TabControl的是的SelectedItem

You could bind the ItemsSource of the TabControl to be the SelectedItem of the DataGrid using element binding.

<TabControl ItemsSource="{Binding ElementName=myDataGrid, Path=SelectedItem.Solutions}">

这篇关于有一个DataGrid和一个TabControl的WPF MVVM主详细视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆