Home › Forums › WPF controls › Xceed DataGrid for WPF › Adding a custom cell editor via code.
Hi all.In my grid the columns are dinamically added via code.How could I use a Custom cell editor for those columns? I.e: a slider?
Thx for now
Imported from legacy forums. Posted by Ricardo (had 615 views)
You can add the column editors when you create the columns:
Column myNewColumn = new Column();myNewColumn.CellEditor = xxx;
Where xxx can be:
this.Resources[ “myEditor” ] if the editor is present in the XAML resourcesOR myCellEditor where myCellEditor is a CellEditor that was created through code.
Imported from legacy forums. Posted by Marcus [Xceed] (had 202 views)
it´s still not very clear.
Let´s say that i have a slider.
How would I add it as a CellEditor via C#?
I mean, I know I need to use the CellEditor.EditTemplate property.But it expects a DataTemplate, how can i transform a Slider into DataTemplate?
Thx for now.
Imported from legacy forums. Posted by Ricardo (had 373 views)
Normally, you would have to create you DataTemplate in XAML for this kind of scenarios (you can refer to the documentation on how to create your own CellEditors in XAML ).
But there is an alternate way, that works through code… However, be aware that Microsoft has marked this way as “deprecated” in its documentation.
DataTemplate myEditorTemplate = new DataTemplate();myEditorTemplate.VisualTree = new FrameworkElementFactory( typeof( Slider ) );
CellEditorBindingExtension cellEditorBinding = new CellEditorBindingExtension();
myEditorTemplate.VisualTree.SetBinding( Slider.ValueProperty, cellEditorBinding.ProvideValue( null ) );
For further details, I recommend reading the SDK documentation on FrameworkElementFactory.
Imported from legacy forums. Posted by Marcus [Xceed] (had 4003 views)