更新
This commit is contained in:
35
DateGridColumnComboBoxBindingEnumDescription/windows.xaml
Normal file
35
DateGridColumnComboBoxBindingEnumDescription/windows.xaml
Normal file
@@ -0,0 +1,35 @@
|
||||
<Window.Resources>
|
||||
<!-- local代表实例化该类,x:key表示实例化的名称,type是该实例的属性 -->
|
||||
<local:EnumDescriptionConvert x:Key="enumItems" Type="{x:Type local:myEnum}" />
|
||||
</Window.Resources>
|
||||
<Grid>
|
||||
<DataGrid
|
||||
x:Name="dg"
|
||||
AutoGenerateColumns="False"
|
||||
CanUserAddRows="False">
|
||||
<DataGrid.Columns>
|
||||
<!-- 绑定的是这个枚举类集合 -->
|
||||
<!-- 通过Converter把Description的Attribute作为选择项 -->
|
||||
<DataGridComboBoxColumn
|
||||
Header="Combobox"
|
||||
ItemsSource="{Binding Source={StaticResource enumItems}}"
|
||||
SelectedValueBinding="{Binding myEnum, Converter={StaticResource enumItems}, Mode=TwoWay}" />
|
||||
</DataGrid.Columns>
|
||||
</DataGrid>
|
||||
</Grid>
|
||||
|
||||
private ObservableCollection<Model> source = new ObservableCollection<Model>();
|
||||
|
||||
public MainWindow()
|
||||
{
|
||||
Model item = new Model()
|
||||
{
|
||||
myEnum = myEnum.BarFoo,
|
||||
Name = "X"
|
||||
};
|
||||
|
||||
source.Add(item);
|
||||
InitializeComponent();
|
||||
|
||||
dg.ItemsSource = source;
|
||||
}
|
||||
Reference in New Issue
Block a user