【发布时间】:2015-08-29 11:32:40
【问题描述】:
我有点卡在这里..搜索了两天,没有找到解决方案。
我想要实现的是 DataGridComboBoxColumn 的行为。
我需要它的DisplayMemberPath、SelectedValuePath 和SelectedValueBinding 属性..
我的 UserControl 类似于 CellEditingTemplate 中的 ComboBox
和CellTemplate中的TextBlock。
我在代码中做所有这些,因为这些列可能不一定存在..
这是我定义 TemplateColumn 的地方:
DataGridTemplateColumn tcol = new DataGridTemplateColumn();
tcol.Header = "accCust";
FrameworkElementFactory texttablF = new FrameworkElementFactory(typeof(TextTableBox));
texttablF.SetValue(TextTableBox.TableSourceProperty, accTable.DefaultView);
FrameworkElementFactory tb = new FrameworkElementFactory(typeof(TextBlock));
texttablF.SetBinding(TextBlock.TextProperty, new Binding("Account"));
tcol.CellTemplate = new DataTemplate(typeof(DataGridCell)) { VisualTree = tb };
tcol.CellEditingTemplate = new DataTemplate(typeof(DataGridCell)) { VisualTree = texttablF };
我有两个问题:
- TextBlock 显示DataGrid 表中的ID,我希望它显示
DisplayMemberPath中指定的值,我不知道如何实现。 -
DependencyProperty
TableSource在通过 FrameworkElement.setValue 完成时不起作用。它在以正常方式完成时起作用, 即TextTableBox ttb = new TextTableBox(); ttb.TableSource = src_table.DefaultView;
我希望你清楚我的问题是什么。我真正想要的是用我的 UserControl 替换 DataGridComboColumn 中的 ComboBox。
在此先感谢 :) 如果这是一个糟糕的问题,我很抱歉。我是 WPF 新手,正在上高中。
【问题讨论】:
-
什么是TextTableBox?
-
那是我的 UserControl.. :)
-
最好能得到更多关于它的信息。例如 - 它是从哪里继承的?
-
TextTableBox 是一个与 ComboBox 控件非常相似的控件,只是它的 Popus 显示的是 DataGrid 而不是 StackPanel 中的项目列表。该控件继承自 UserControl 类,而不是 ComboBox :)
标签: wpf datagrid datagridtemplatecolumn