首页 > 其他 > 详细

DataGrid添加ComboBox模板列

时间:2015-05-12 22:17:48      阅读:274      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!