Silverlight 3 DataForm - How to populate DataFormC

2019-08-07 18:33发布

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条回答
We Are One
2楼-- · 2019-08-07 18:59

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

查看更多
登录 后发表回答