码迷,mamicode.com
首页 > 其他好文 > 详细

DataGrid添加ComboBox模板列

时间:2015-05-12 22:21:00      阅读:120      评论:0      收藏:0      [点我收藏+]

标签:

首先在添加一个模板列

              <DataGrid.Columns>
                    <DataGridTemplateColumn  Header="ComboBox模板列" >
                        <DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <ComboBox ItemsSource="{Binding Source={StaticResource ResourceKey=SelectedTypeResource}}" DisplayMemberPath="Element[ItemName].Value" Text="{Binding Element[SelectedType].Value, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"></ComboBox>
                            </DataTemplate>
                        </DataGridTemplateColumn.CellTemplate>
                    </DataGridTemplateColumn>
                </DataGrid.Columns>

申明一个ComboBox下拉菜单绑定内容的数组

public static XElement[] SelectedTypeResource = new XElement[] { 
new XElement("Item",new XElement("ItemName","下拉菜单一"),new XElement("ItemCode",1)),
new XElement("Item",new XElement("ItemName","下拉菜单二"),new XElement("ItemCode",2))
};

 

在构造函数中加入本地资源字典里

public MainWindow()
{
InitializeComponent();
(this.Resources["SelectedTypeResource "] as ObjectDataProvider).ObjectInstance = SelectedTypeResource ;

}

 

在设计器里面

<Window.Resources>
<ObjectDataProvider x:Key="SelectedTypeResource "></ObjectDataProvider>
</Window.Resources>

 

DataGrid添加ComboBox模板列

标签:

原文地址:http://www.cnblogs.com/wujiaqi-IT/p/4498532.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!