在数据网格上使用数据绑定组合框 [英] Using a databound combobox on a datagrid
本文介绍了在数据网格上使用数据绑定组合框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
对于一个数据网格,我想使用一个数据绑定的组合框来设置具有该组合框的选定值的属性的值。我该怎么做呢?
With a datagrid, I want to use a databound combobox to set the value of a property with the combobox's selected value. How would I go about doing that?
欢呼
推荐答案
此使用WPF DataGrid的CellTemplate功能可以轻松实现:
This can easily be achieved using the WPF DataGrid's CellTemplate features:
<DataGrid.Columns>
<DataGridTemplateColumn Header="My Column">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding MyBoundField}"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
<DataGridTemplateColumn.CellEditingTemplate>
<DataTemplate>
<ComboBox ItemsSource="{Binding MyOptionsSource}" IsEditable="False"/>
</DataTemplate>
<DataGridTemplateColumn.CellEditingTemplate>
</DataGridTemplateColumn>
<DataGrid.Columns/>
现在只需处理ComboBox SelectionChanged事件并通过赋予DataGrid键盘焦点来强制执行Commit:)
Now just handle the ComboBox SelectionChanged event and force a Commit by giving the DataGrid keyboard focus :)
玩得开心。
这篇关于在数据网格上使用数据绑定组合框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文