这似乎并没有让我的组合框显示更友好的名称。我不确定我做错了什么。
<ComboBox ItemsSource="{Binding MyTypes, Mode=OneTime}"
SelectedItem="{Binding SelectedType}"/>
public sealed class MyType : IMyInterface
{
public override string ToString()
{
return "Friendlier Name";
}
}
另外,我尝试使用IValueConverter
(不起作用)...
<ComboBox ItemsSource="{Binding MyTypes, Mode=OneTime}"
MemberDisplayPath="{Binding Converter={StaticResource MyConverter}}"
SelectedItem="{Binding SelectedType}"/>
[ValueConversion(typeof(Type), typeof(String))]
public sealed class MyConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var type = value as Type;
if (type == null)
{
return DependencyProperty.UnsetValue;
}
return type.ToString();
}
...
}
问题是 IValueConverter 似乎只能获取我的 ViewModel,因为它的值被传入......所以不确定那里发生了什么。