我们将 DataGridTemplateColumn 添加到 DataGrid,并使用通过创建的组合框填充 DGTC
DataGridTemplateColumn dgtc = new DataGridTemplateColumn();
FrameworkElementFactory comboBoxFactory = new FrameworkElementFactory(typeof(ComboBox));
/* snip */
DataTemplate cellEditTemplate = new DataTemplate();
cellEditTemplate.VisualTree = comboBoxFactory;
dgtc.CellEditingTemplate = cellEditTemplate;
dgtc.SortMemberPath = string.Format($"{descr.BindingPropertyName}");
dgtc.Header = descr.BindingPropertyName;
稍后,我们需要更改 TextSearch.TextPathProperty 等属性。
我们从 DataGridTemplateColumn 中获取 CellEditingTemplate;问题是,“如何将 CellEditingTemplate.VisualTree 作为组合框访问”?
此代码表明 VisualTree 是一个组合框:
var cellEditingTemplate = dgtc.CellEditingTemplate;
var propsVals = cellEditingTemplate.GetPropertyValues();
foreach (KeyValuePair<string, string> pair in propsVals)
{
Debug.WriteLine($"Key: {pair.Key} value: {pair.Value}");
}
输出:
键:类型值:Windows.Controls.ComboBox
似乎没有办法将 VisualTree 转换为 ComboBox。
我在看什么?
谢谢 -