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,
               }
           };
}
Parents
No Data
Reply
  • 6365
    Offline posted

    Hello robsonj,

    Thank you for the code-snippet you have provided.

    In order to manually specify the visible columns of the XamMultiColumnComboEditor when it is defined as a template for the CellValuePresenterStyle of a specific field in the XamDataCards, you can refer to the Columns collection of the editor and add new TextBoxColumn instances by specifying their respective Key.

    XAML:

    <igDP:XamDataCards.Resources>
        <Style TargetType="ig:XamMultiColumnComboEditor">
            <EventSetter Event="Loaded" Handler="MultiCombo_Loaded" />
        </Style>
    </igDP:XamDataCards.Resources>

    Code-behind:

    private void MultiCombo_Loaded(object sender, RoutedEventArgs e)
    {
        // Add a columns to the XamMultiColumnComboEditor when it has loaded
        // (NOTE: Additional checks will be required to identify the ItemsSource of the Combo
        //  and choose the appropriate column keys.)
        //
        (sender as XamMultiColumnComboEditor).Columns.Add(new TextComboColumn() { Key = "Name" });
    }

    I have attached a sample that uses the approach from above.

    If you have any questions, please let me know.

    XamDataCards_sample.zip
Children