我有一个List集合,当它被分配时,它有一个类型为short number的集合。但是,如何在WPF ComboBox上显示数字?
我通常在XAML中使用DisplayMemberPath属性,但我不能声明属性,因为它不是我自己的集合。 (如List(T)....)
XAML
<ComboBox HorizontalAlignment="Left"
ItemsSource="{Binding TheList}"
// This is wrong of course
DisplayMemberPath="."
C#
public List<short> TheList
{
get
{
return m_ListSID;
}
set
{
m_ListSID = value;
}
}
任何帮助都会感激不尽。
修改
绝对愚蠢...所有答案当然都是真实有道理的,只是因为我忘了触发集合的更新源
ItemsSource="{Binding TheList, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
道歉
由于
答案 0 :(得分:1)
<ComboBox HorizontalAlignment="Left" ItemsSource="{Binding TheList}" DisplayMemberPath="" />
答案 1 :(得分:1)
您不需要DisplayMemberPath
这就足够了:
<ComboBox HorizontalAlignment="Left" ItemsSource="{Binding TheList}"/>
答案 2 :(得分:1)
根本不设置DisplayMemberPath
,short
应转换为string
<ComboBox HorizontalAlignment="Left" ItemsSource="{Binding TheList}"/>
如果默认情况下未提供模板,WPF将在项目上调用ToString()
。
修改强>
您可以在ContentPresenter
MSDN页面