【发布时间】:2012-02-27 22:36:12
【问题描述】:
我想将添加到集合中的元素的类成员绑定到DisplayMemberPath。我将ObservableCollection 绑定到ComboBox.ItemSource 并希望在组合框列表中显示属性name,它是我的班级AxisBase 的成员。
这是我的代码:
private ObservableCollection<AxisBase> axis { get; set; }
axis我用来保存以下类的元素
class AxisBase
{
...
public string name { get; set; }
...
}
这就是我的 xaml 的样子
<ComboBox Name="comboBox_AchsenListe" DisplayMemberPath="{Binding ElementName=axis, Path=AxisBase.name}" ItemsSource="{Binding ElementName=_MainWindow, Path=axis}"</ComboBox>
有谁知道如何将name 绑定到DisplayMemberPath?
【问题讨论】:
-
看看我的答案更新。我举个例子。
-
非常感谢。我不得不将我的 ObservableCollection 更改为
public,这最终使它工作。只是一些小事弄乱了整个代码:) 谢谢!
标签: c# wpf data-binding collections