3 回答

TA貢獻(xiàn)1829條經(jīng)驗(yàn) 獲得超6個(gè)贊
我使用了另一種使用MarkupExtension的解決方案。
我做了一個(gè)提供項(xiàng)目來源的課程:
public class EnumToItemsSource : MarkupExtension
{
private readonly Type _type;
public EnumToItemsSource(Type type)
{
_type = type;
}
public override object ProvideValue(IServiceProvider serviceProvider)
{
return Enum.GetValues(_type)
.Cast<object>()
.Select(e => new { Value = (int)e, DisplayName = e.ToString() });
}
}
這幾乎都是......現(xiàn)在在XAML中使用它:
<ComboBox DisplayMemberPath="DisplayName"
ItemsSource="{persons:EnumToItemsSource {x:Type enums:States}}"
SelectedValue="{Binding Path=WhereEverYouWant}"
SelectedValuePath="Value" />
將“枚舉:狀態(tài)”更改為您的枚舉
- 3 回答
- 0 關(guān)注
- 939 瀏覽
添加回答
舉報(bào)