Specify a ValueEditor for a Field in xamDataPresenter

Glossary Item Box

Infragistics(R) NetAdvantage(R) for WPF

Specify a ValueEditor for a Field in xamDataPresenter

The xamDataPresenter™ control can use any NetAdvantage for WPF editor to display a Field's content. These editors all derive from the ValueEditor class. The EditorType property off the FieldSettings only accepts editors that derive from the ValueEditors class. When you set the EditorType property, you can also set the EditAsType property. The EditAsType property informs xamDataPresenter what type of validation to do when a customer is editing a value in a Cell. This property is crucial if your data source doesn't have types specified for Fields. If your data source doesn't set the type, xamDataPresenter won't validate data because all values will be treated as type object. Therefore, if xamDataPresenter knows what type a Field should be, it will perform basic type validation.

Using the EditorType and EditAsType properties together ensures that data validation is performed on data input. This topic explains how to expand a Field to use the FieldSettings object. This topic also assumes you have completed one of the three following topics:

Note: The xamNumericEditor mentioned in this topic is only available in the NetAdvantage for WPF Full version. The concepts shown here though can be applied to the editors available in the Express version.

These topics show you how to access xamDataPresenter's Field and FieldLayouts in XAML. Since we are setting the FieldSettings off the Field, you will need to have access to the xamDataPresenter's FieldLayouts.

  1. Add two additional namespace declarations to your Page/Window's opening tag. The first namespace declaration allows access to the mscorlib which you will use to define data types. The second namespace declaration allows access to the NetAdvantage for WPF editors assembly which you will use to set the EditorType.
  2. In XAML:

    xmlns:sys="clr-namespace:System;assembly=mscorlib"
    xmlns:igEditors="http://infragistics.com/Editors"
    

  3. To access the FieldSettings object, specify the Field.Settings object off the Field. The EditAsType and EditorType properties you will set are contained within the Field.Settings object.

    The following XAML shows you how to set the EditAsType and EditorType properties. They are both of Type, so you need to use the Microsoft® Windows® Presentation Foundation Type syntax to specify the value. Set the "ProductName" Field as Type String and use the xamTextEditor. Set the "Quantity" and "Discount" Fields as Type Int32 and use the xamNumericEditor.
  4. In XAML:

    ...
            <igDP:Field Name="ProductName" >
                    <igDP:Field.Settings>
                            <igDP:FieldSettings EditAsType="{x:Type sys:String}" 
                              EditorType="{x:Type igEditors:XamTextEditor}"/>
                    </igDP:Field.Settings>
            </igDP:Field>
            <igDP:Field Name="CostPerUnit" />
            <igDP:Field Name="Quantity" >
                    <igDP:Field.Settings>
                            <igDP:FieldSettings EditAsType="{x:Type sys:Int32}" 
                              EditorType="{x:Type igEditors:XamNumericEditor}"/>
                    </igDP:Field.Settings>
            </igDP:Field>
            <igDP:Field Name="Discount" >
                    <igDP:Field.Settings>
                            <igDP:FieldSettings EditAsType="{x:Type sys:Int32}" 
                              EditorType="{x:Type igEditors:XamNumericEditor}"/>
                    </igDP:Field.Settings>
            </igDP:Field>
            <igDP:Field Name="ShipAndHandle"/>
    ...
    

  5. Build and run the project. The first screen shot comes from Customizing a Field topic. If you compare it to the second one, which is the results of the above code, you can can tell that the xamNumericEditors are being used because the numbers in the Quantity and Discount columns are right aligned.


E-mail your feedback on this topic.

Opinion about our help? Take our survey.

Copyright © 2003-2007 Infragistics, Inc. All rights reserved.

Build Version: 7.1.20071.1320