Get the object created by new FrameworkElementFactory(typeof(T))

238 Views Asked by At

We are adding a DataGridTemplateColumn to a DataGrid, and populating the DGTC with a combobox created via

 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;

Later, we need to change properties such as the TextSearch.TextPathProperty.
We get the CellEditingTemplate from the DataGridTemplateColumn; the question is, "How to access the CellEditingTemplate.VisualTree as a combobox"?

This code suggests that the VisualTree is a combobox:

        var cellEditingTemplate = dgtc.CellEditingTemplate;  
        var propsVals = cellEditingTemplate.GetPropertyValues();
        foreach (KeyValuePair<string, string> pair in propsVals)
        {
            Debug.WriteLine($"Key: {pair.Key}     value: {pair.Value}");
        }

Output:
Key: Type value: Windows.Controls.ComboBox

It appears there is no way to cast the VisualTree to ComboBox.
What am I overlooking?
Thanks --

0

There are 0 best solutions below