このトピックに興味があります: コンボボックスとObjectdataproviderを使って実行しました。 "ItemsSource"は構造体ですが、 "SelectedItem"は別の場所に書き込まれます。
<!--resources-->
<ObjectDataProvider x:Key="StructValues"
MethodName="GetValues"
ObjectType="{x:Type local:MyStruct}">
<ObjectDataProvider.MethodParameters>
<x:Type TypeName="local:MyStruct" />
</ObjectDataProvider.MethodParameters>
</ObjectDataProvider>
<ComboBox Margin="0,5"
VerticalAlignment="Center"
ItemsSource="{Binding Source={StaticResource StructValues}}"/>
そして、これは構造体がどのように見えるかです:: ここにある
public struct MyStruct
{
public const string A = "A";
public const string B = "B";
public const string C = "C";
public static IEnumerable GetValues(Type type)
{
List<String> retVals = new List<string>();
FieldInfo[] fi = type.GetFields();
foreach (FieldInfo info in fi)
{
retVals.Add(info.Name);
}
return retVals;
}
}
あなたは構造体とクラスの違いを知っていますか? –