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>

代码:

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

我需要做什么来填充和初始化下拉菜单?

4

1 回答 1

1

答案是使用转换器:

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

并在表单 Loaded 事件上设置 ItemsSource

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

完整的故事请看这里:

在 Silverlight-3-Customization 中创建丰富的数据表单

于 2009-06-09T17:27:08.107 回答