views:

1761

answers:

1

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?

A: 

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

Sam Mackrill