XAML
<df:DataForm x:Name="MobCrud"
AutoEdit="True"
AutoCommit="True"
AutoGenerateFields="False"
VerticalAlignment="Top"
CommandButtonsVisibility="All"
Header="Mob Details"
CanUserAddItems="True"
CanUserDeleteItems="True"
CurrentItem="{StaticResource newMob}"
>
<df:DataForm.Fields>
<df:DataFormTextField Binding="{Binding Name}" FieldLabelContent="Name" />
<df:DataFormTextField Binding="{Binding Title}" FieldLabelContent="Title"/>
<df:DataFormComboBoxField x:Name="AuraList" Binding="{Binding Aura}" FieldLabelContent="Aura"/>
</df:DataForm.Fields>
代码:
public enum Auras
{
Holy,
Fire,
Frost,
}
public class MobDetail : IEditableObject
{
public string Name { get; set; }
public string Title { get; set; }
public Auras Aura { get; set; }
public override string ToString() { return Name; }
public void BeginEdit(){}
public void EndEdit(){}
public void CancelEdit(){}
}
DataForm ItemsSource绑定到ObservableCollection()
我需要做什么来填充和初始化下拉列表?
答案 0 :(得分:1)
答案是使用转换器:
<df:DataFormComboBoxField
x:Name="AuraList"
Binding="{Binding Aura, Mode=TwoWay,
Converter={StaticResource enumSelectedValueConverter}}"
FieldLabelContent="Aura"/>
并在表单Loaded event
上设置ItemsSource(MobCrud.Fields[2] as DataFormComboBoxField).ItemsSource =
Enums.GetStringArray(typeof(Auras));
请参阅此处了解完整报道: