我需要将数据网格中 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>
一切正常。诀窍在哪里,我应该如何实现我需要的功能?谢谢你。