我不确定这是否可能。我已经创建了一个这样的组合框......
<ComboBox Name="testType"
Margin="0,5,0,0"
IsTextSearchEnabled="True"
DisplayMemberPath="Description"
SelectedValue="{Binding MyClass.Id, Mode=TwoWay}"
SelectedValuePath="Id"/>
后面的代码会加载可用的选项...
DataTable testCatList = TestTypeBase.GetAll();
testType.ItemsSource = testCatList.DefaultView;
以便正确显示 MyClass 中的所有项目。当用户做出选择时,MyClass 中的 Id 字段会按预期进行更新。伟大的。
这是我的问题:我的 testCatList 包含每一行的 Id 和 Description,我希望这两个字段都绑定到当前的 MyClass 实例。所以这就是我尝试过的:
<ComboBox Name="testType"
Margin="0,5,0,0"
IsTextSearchEnabled="True"
DisplayMemberPath="Description">
<ComboBox.SelectedValue>
<MultiBinding Converter="{???}">
<Binding Path="MyClass.Id" Mode="TwoWay"/>
<Binding Path="MyClass.Description" Mode="TwoWay"/>
</MultiBinding>
</ComboBox.SelectedValue>
</ComboBox>
在这里,我想将 MyClass.Id 设置为选定的 Id,并将 MyClass.Description 设置为选定的描述。如您所见,我已经删除了 SelectedValuePath,因为我不再需要 Id。但我不知道转换器使用什么(见上面的问号)。
任何想法,哦 StackOverflow 专家?谢谢。