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
60
How to add a converter to a XamDataPresenter field using c# code
posted

I am dynamically building the field layout for the XamDataPresenter and I need to add a converter to a field. All the examples I find show how to do it with xaml I need to add the converter in code, C#. Here is the code that I am using to define the field layout

//create a field

Infragistics.Windows.DataPresenter.Field field = new Infragistics.Windows.DataPresenter.Field();

field.Name = row.FieldName;

field.Label = row.ColumnHeader;

field.IsPrimary = row.PrimaryField;

field.Settings.CellMinWidth = row.ColumnWidth;

field.Settings.CellMaxWidth = row.ColumnWidth;

field.Settings.LabelMinWidth = row.ColumnWidth;

field.Settings.LabelMaxWidth = row.ColumnWidth;

field.Visibility = (
Visibility)row.Visibility;

//add the field to the fields collection

fieldLayout.Fields.Add(field);

  

How do I add a converter to the field? The converter could be any converter, but in this instance i need a boolean to yes/no string converter.

 

Thanks.

 

  • 339
    posted

    Hello, I assume you are able to create the converter in XAML first? If so you can assign it as follows in C#.

    field.Settings.CellValuePresenterStyle =
                                        xamGrid.Resources["myStyle"] as Style;

    Cheers,

    Jamie