【发布时间】:2018-06-16 07:12:42
【问题描述】:
所以,我有一个模型
public class MyModel
{
public string Id { get; }
public string Representation { get; }
public static IEnumerable<MyModel> MyModels() { ... }
}
以 MyModels 作为 ItemSource 的组合框,其中 MyModel.Representation 定义为显示属性
<ObjectDataProvider x:Key="myModelsData"
ObjectType="{x:Type models:MyModel}"
MethodName="MyModels"/>
<ComboBox Name="MyBox"
ItemsSource="{Binding Source={StaticResource myModelsData}}"
DisplayMemberPath="Representation"/>
现在,我正在执行多重绑定,我不想引用 MyModel.Representation,而是引用 MyModel.Id。如何做到这一点?
我现在唯一知道的方法是
<Button Command="{Binding MyCommand}">
<Button.CommandParameter>
<MultiBinding Converter="{StaticResource myModelConverter }">
<Binding ElementName="MyBox" Path="Text"/>
</MultiBinding>
</Button.CommandParameter>
</Button>
但 Text 包含 MyModel.representation。那么,如何喜欢呢?
<Binding Path={MyBox.SelectedItem.Id}/>
【问题讨论】:
标签: c# wpf data-binding combobox