WPF-DataGridComboBoxColumn的示例 [英] WPF - example with DataGridComboBoxColumn

查看:101
本文介绍了WPF-DataGridComboBoxColumn的示例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2列的数据网格。一栏包含角色信息,另一栏应包含一个带有可用用户列表的组合框。组合框中的数据与第一列中的数据无关。

I have a datagrid with 2 columns. One column contains role information, the other column should have a combo box with a list of available users. The data in the combobox is unrelated to the data in the first column.

组合框没有数据上下文,只有项源,而且似乎也不能使用绑定,这让我很不高兴。

I'm thrown off by the fact that the combobox does not have a datacontext, only an itemsource and I can't seem to use binding either.

对表和组合框中的数据使用两个不同数据集的方法是什么?

What is the method that uses two different data sets for the data in a table and in the combo box?

推荐答案

数据网格中的列没有数据上下文,因为它们从未添加到可视化树中。听起来有点奇怪,但请查看 vinces博客,它是视觉布局的一个很好的例子。绘制网格后,单元格便具有数据上下文,您可以使用常规绑定(不是静态资源)在其中设置组合框项目源。

the columns in the datagrid dont have a datacontext, as they are never added to the visual tree. sound a bit wierd but have a look at vinces blog, its got a good example of the visual layout. once the grid is drawn the cells have a data context and you can set the combo boxes items source in them using normal bindings (not static resources..)

您可以访问

   <dg:DataGridComboBoxColumn>
      <dg:DataGridComboBoxColumn.EditingElementStyle>
        <Style TargetType="ComboBox">
            <Setter Property="ItemsSource" Value="{Binding Path=MyBindingPath}" />
        </Style>
      </dg:DataGridComboBoxColumn.EditingElementStyle>
   </dg:DataGridComboBoxColumn>

看看此处,还有此处一些代码

这篇关于WPF-DataGridComboBoxColumn的示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆