Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
800
Building Columns Programatically
posted

I am building a XamMultiSelectionComboEditor programatically for use inside a XamDataCards control (part of our applications dynamic property editor infrastructure). I have been able to make the editor show up in the data card, and if I enable auto generation of columns, it shows my data, but I am trying to figure out how I can add a TextComboColumn programatically.

Any help would be appreciated, what I have so far is below (note auto egneration is false in this snippet).

Thanks

Jonathan

public static Field GetComboEditor(string name, string label, object values, string displayMemberPath, IValueConverter converter, ValueConstraint constraint = null, string tooltip = null)
{
    var editor = new FrameworkElementFactory(typeof(XamMultiColumnComboEditor));
    editor.SetValue(XamMultiColumnComboEditor.AutoGenerateColumnsProperty, false);
    editor.SetValue(XamMultiColumnComboEditor.AllowMultipleSelectionProperty, false);
    editor.SetValue(XamMultiColumnComboEditor.ItemsSourceProperty, values);
    editor.SetValue(XamMultiColumnComboEditor.DisplayMemberPathProperty, displayMemberPath);
    editor.SetValue(XamMultiColumnComboEditor.SelectedItemsResetButtonVisibilityProperty, Visibility.Collapsed);
 
// BUILD COLUMNS AND ATTACH TO THE editor HERE SOME HOW?
    var ctrlTemplate = new ControlTemplate(typeof(CellValuePresenter))
                       {
                           VisualTree = editor
                       };
 
    var cvpStyle = new Style(typeof(CellValuePresenter));
    cvpStyle.Setters.Add(new Setter(Control.TemplateProperty, ctrlTemplate));
 
    return new Field
           {
               Name = name,
               Label = label,
               IsExpandable = false,
               ToolTip = tooltip,
 
               DataType = typeof(object),
               Settings =
               {
                   CellValuePresenterStyle = cvpStyle,
               }
           };
}