我把我的枚举投射到一个组合框中。但现在我想绑定到一个选定项目,但不确定类型是什么。
xaml方:
<ObjectDataProvider x:Key="MyEnumDataProvider" MethodName="GetValues" ObjectType="{x:Type System:Enum}">
<ObjectDataProvider.MethodParameters>
<x:Type TypeName="model:ContactMethod+Channels"></x:Type>
</ObjectDataProvider.MethodParameters>
</ObjectDataProvider>
<ComboBox ItemsSource="{Binding Source={StaticResource MyEnumDataProvider}}" SelectedItem="ContactType" Width="100"></ComboBox>
ContactMethod.cs
public enum Channels { Phone, Website, Email, Skype, Cell, Fax }
MVVM方面:
这是我遇到麻烦的地方,我是否必须转换所选的“对象”,或者有一个简单的方法。
公开 _ _ ContactType {get;设置;}
下划线是什么?
答案 0 :(得分:0)
SelectedItem将是Channels
类型public Channels ContactType {get; set;}
你将需要像这样绑定到Xaml中的属性
<ComboBox ItemsSource="{Binding Source={StaticResource MyEnumDataProvider}}" SelectedItem="{Binding ContactType, Mode=TwoWay}" Width="100"></ComboBox>