Silverlight 3 DataForm - How to populate DataFormComboBoxField from enumeration

▼魔方 西西 提交于 2019-12-11 07:46:17

问题


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>

Code:

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(){}
}

The DataForm ItemsSource is bound to an ObservableCollection()

What do I need to do to populate and initialize the dropdown?


回答1:


Answer is to use a converter:

<df:DataFormComboBoxField  
     x:Name="AuraList"
     Binding="{Binding Aura, Mode=TwoWay,
               Converter={StaticResource enumSelectedValueConverter}}"
     FieldLabelContent="Aura"/>

and set the ItemsSource on the form Loaded event

(MobCrud.Fields[2] as DataFormComboBoxField).ItemsSource =
                 Enums.GetStringArray(typeof(Auras));

See here for the full story:

Creating-Rich-Data-Forms-in-Silverlight-3-Customization



来源:https://stackoverflow.com/questions/971243/silverlight-3-dataform-how-to-populate-dataformcomboboxfield-from-enumeration

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!