使用 mvvmlight 在 win8 平台上将枚举绑定到组合框
Binding enum to combobox at win8 platform using mvvmlight
我正在尝试将枚举绑定到组合框,因此我尝试遵循建议使用此代码的指南:
<Page.Resources>
<ObjectDataProvider MethodName="GetValues"
ObjectType="{x:Type sys:Enum}"
x:Key="ExampleEnumValues">
<ObjectDataProvider.MethodParameters>
<x:Type TypeName="ExampleEnum" />
</ObjectDataProvider.MethodParameters>
</ObjectDataProvider>
</Page.Resources>
问题是它说 "objectdataprovider is not supported in a windows app project"。还有另一种方法吗?在此先感谢大家。
好吧,如果你想在组合框中显示枚举值,你所要做的就是:
在您的视图模型中:
public Array SomeName { get; set; }
//c'tor
public viewModelName()
{
SomeName = Enum.GetValues(typeof(MyEnumType));
}
在您看来:
<ComboBox ItemsSource="{Binding SomeName}" ></ComboBox>
我正在尝试将枚举绑定到组合框,因此我尝试遵循建议使用此代码的指南:
<Page.Resources>
<ObjectDataProvider MethodName="GetValues"
ObjectType="{x:Type sys:Enum}"
x:Key="ExampleEnumValues">
<ObjectDataProvider.MethodParameters>
<x:Type TypeName="ExampleEnum" />
</ObjectDataProvider.MethodParameters>
</ObjectDataProvider>
</Page.Resources>
问题是它说 "objectdataprovider is not supported in a windows app project"。还有另一种方法吗?在此先感谢大家。
好吧,如果你想在组合框中显示枚举值,你所要做的就是:
在您的视图模型中:
public Array SomeName { get; set; }
//c'tor
public viewModelName()
{
SomeName = Enum.GetValues(typeof(MyEnumType));
}
在您看来:
<ComboBox ItemsSource="{Binding SomeName}" ></ComboBox>