Version

Binding Cell Settings to Data Item Properties (xamDataGrid)

Topic Overview

Purpose

This topic describes how to bind cell settings to data item properties using the CellBindings collection property in the xamDataPresenter™ controls.

Required background

The following topics are prerequisites to understanding this topic:

Topic Purpose

This section defines the major elements that constitute the controls that make up The Data Presenter Family.

This topic describes how to add a xamDataGrid control to your page.

This section lists the topics written specifically to help you access data using xamDataGrid control.

In this topic

This topic contains the following sections:

Binding Cell Settings to Data Item Properties

Overview

Use the CellBindings collection property to facilitate the binding of a cell settings to properties exposed off the associated data item.

Create a CellBinding instance for every field’s cell property which you would like to bind to a data item property and add it to the CellBindings collection.

Note
Note

Since the context of the CellBinding is the cell’s DataRecord, use the following syntax to specify the path to a data item property named "MyProperty": “ DataItem.MyProperty ”.

Property settings

The following table maps the desired configuration to the property settings that manage it.

In order to: Use this property: And set it to:

Configure a collection of field’s cells bindings to MVVM properties

Specify that the CellBinding targets the ValueEditor instance within the cell’s CellValuePresenter

Editor

Specify that the CellBinding targets the cell’s CellValuePresenter

CellValuePresenter

Specify the name of a target’s property to bind

string

This property should be non-read-only DependencyProperty.

Specify the actual binding markup

BindingBase

Example

The screenshot below demonstrates how a field’s cells would look as a result of the following CellBinding settings:

Property Value

CellValuePresenter

Foreground

{Binding Path=DataItem.Color}

Binding Cell Settings to MVVM properties 1.png

Following is the code that implements this example.

In C#:

public class Car : INotifyPropertyChanged
{
    private string _make;
    public string Make
    {
        get { return _make; }
        set
        {
            if (_make != value)
            {
                _make = value;
                NotifyPropertyChanged("Make");
            }
        }
    }
    private Brush _color;
    public Brush Color
    {
        get { return _color; }
        set
        {
            if (_color != value)
            {
                _color = value;
                NotifyPropertyChanged("Color");
            }
        }
    }
    #region INotifyPropertyChanged Members
    public event PropertyChangedEventHandler PropertyChanged;
    private void NotifyPropertyChanged(String info)
    {
        if (PropertyChanged != null)
        {
            PropertyChanged(this, new PropertyChangedEventArgs(info));
        }
    }
    #endregion
}

In XAML:

<igDP:XamDataGrid x:Name="XamDataGrid1"
                  DataSource="{Binding Path=Cars}">
    <igDP:XamDataGrid.FieldLayoutSettings>
        <igDP:FieldLayoutSettings AutoGenerateFields="False" />
    </igDP:XamDataGrid.FieldLayoutSettings>
    <igDP:XamDataGrid.FieldLayouts>
        <igDP:FieldLayout>
            <igDP:FieldLayout.Fields>
                <igDP:TextField Name="Make">
                    <igDP:TextField.CellBindings>
                        <igDP:CellBinding Property="Foreground"
                                          Target="CellValuePresenter"
                                          Binding="{Binding Path=DataItem.Color}" />
                    </igDP:TextField.CellBindings>
                </igDP:TextField>
            </igDP:FieldLayout.Fields>
        </igDP:FieldLayout>
    </igDP:XamDataGrid.FieldLayouts>
</igDP:XamDataGrid>

Related Topics

The following topics provide additional information related to this topic.

Topic Purpose

This topic describes how to data bind the xamDataPresenter controls to an XmlDataProvider to expose your XML file to the presentation layer of your application.

This topic describes how to data bind the xamDataPresenter controls to an ObjectDataProvider to expose your collection to the presentation layer of your application.

This topic describes how to data bind the xamDataPresenter controls to a DataSet.

This topic describes how to bind the Field, FieldSettings, FieldLayout and FieldLayoutSettings to MVVM properties using the FieldBinding markup extension in the xamDataPresenter controls.

This topic describes how to find the DataRecord object that corresponds to your data item.

This topic describes how to add your data items directly to the xamDataPresenter control’s DataItems collection.

This topic describes how the xamDataPresenter controls display hierarchical data.

This topic describes how to display an image in a Field overriding the CellValuePresenter’s template.

This topic describes how you can iterate through the nested structure of records as well as what kind of record types you may encounter.