【发布时间】:2012-04-07 13:52:00
【问题描述】:
我需要将数据网格中 SelectedItem 的值绑定到:
同一页面组合框的SelectedItem
视图模型中的属性
换句话说:当我在数据网格中选择一行时,组合框中的值应该改变,并且上述属性的值也应该设置为数据网格的选定项的值。
我尝试像这样使用多重绑定:
<DataGrid.SelectedItem>
<MultiBinding Converter="{StaticResource sapConverter}" >
<Binding Path="SelectedSap" Mode="TwoWay"/>
<Binding ElementName="cbSearchCompanyName" Path="SelectedItem" Mode="OneWay"/>
</MultiBinding>
</DataGrid.SelectedItem>
这里的 SelectedSap 是我要更新的属性。但是当我查看转换器中的 values() 时,与 SelectedSap 对应的 value(0) 始终是 Nothing,因此该属性不会按我的意愿改变。 与组合的绑定工作正常。
我尝试在没有多重绑定的情况下对其进行测试。我的意思是,我不关心组合,我只是改变财产的价值。像这样:
<DataGrid.SelectedItem>
<Binding Path="SelectedSap" Mode="TwoWay"/>
</DataGrid.SelectedItem>
一切正常。 诀窍在哪里,我应该如何实现我需要的功能? 谢谢。
【问题讨论】:
-
为什么不直接绑定组合框上的poperty SelectedSap?所以datagrid选中的项目和combox选中的项目将绑定在与视图模式相同的属性上
标签: wpf vb.net datagrid selecteditem multibinding