Question

In my C#/WPF app, I and am trying to bind an Infragistics WPF XamDataGrid to an ObservableCollection. MyViewModel exposes the Model property. When I add the property whose value I want displayed to MyViewModel, everything works fine. Below shows an example where I'm binding to the UnitID property exposed by an instance of a MyViewModel contained in the UnitsOfMeasure ObservableCollection.

If I change "Name" to "Model.Name", at runtime the correct number of rows appears in the data grid, but all fields are blank. No runtime error is raised.

My workaround is to add each property to MyViewModel and reference the property in the Model in each getter and setter. Makes for redundant code, and doesn't agree with Laurent's demo's.

This xaml works:

<igEditors:XamDataGrid Theme="Royale" Grid.Column="2" Grid.Row="1" HorizontalAlignment="Stretch" Margin="2" Name="xamDataGridUnitsOfMeasure" DataSource="{Binding Path=UnitsOfMeasure}"  VerticalAlignment="Stretch">
    <igEditors:XamDataGrid.FieldLayoutSettings>
        <igEditors:FieldLayoutSettings AutoGenerateFields="False"/>
            </igEditors:XamDataGrid.FieldLayoutSettings>
                <igEditors:XamDataGrid.FieldLayouts>
                    <igEditors:FieldLayout IsDefault="True">
                        <igEditors:FieldLayout.Fields>
                           <igEditors:Field Name="UnitID" Label="UOM ID">
                              <igEditors:Field.Settings>
                                 <igEditors:FieldSettings AllowEdit="False"/>
                              </igEditors:Field.Settings>
                           </igEditors:Field>
  .
  .
  .

Changing UnitID to Model.UnitID does not work:

<igEditors:XamDataGrid Theme="Royale" Grid.Column="2" Grid.Row="1" HorizontalAlignment="Stretch" Margin="2" Name="xamDataGridUnitsOfMeasure" DataSource="{Binding Path=UnitsOfMeasure}"  VerticalAlignment="Stretch">
    <igEditors:XamDataGrid.FieldLayoutSettings>
        <igEditors:FieldLayoutSettings AutoGenerateFields="False"/>
            </igEditors:XamDataGrid.FieldLayoutSettings>
                <igEditors:XamDataGrid.FieldLayouts>
                    <igEditors:FieldLayout IsDefault="True">
                        <igEditors:FieldLayout.Fields>
                           <igEditors:Field Name="Model.UnitID" Label="UOM ID">
                              <igEditors:Field.Settings>
                                 <igEditors:FieldSettings AllowEdit="False"/>
                              </igEditors:Field.Settings>
                           </igEditors:Field>
  .
  .
  .

Here's part of the ViewModel that is functional:

public class UnitOfMeasureViewModel : ViewModelBase
{
    /// <summary>
    /// Initializes a new instance of the UnitOfMeasureViewModel class.
    /// </summary>
    public UnitOfMeasureViewModel(UnitOfMeasure model)
    {
        Model = model;
        //Model.PropertyChanged += (s, e) =>
        //    {
        //        RaisePropertyChanged(e.PropertyName);
        //    };
    }

    public UnitOfMeasure Model
    {
        get;
        private set;
    }

    public string UnitID
    {
        get
        {
            return Model.UnitID;
        }

        set
        {
            Model.UnitID = value;
        }
    }
Was it helpful?

Solution

The nested binding is supported by XamGrid control - http://help.infragistics.com/Help/NetAdvantage/WPF/2012.1/CLR4.0/html/xamGrid.html

Or

Refer to this link of Infragistics help -http://www.infragistics.com/community/forums/t/67603.aspx

This will help you do the nested binding

Else => Do you want to extract interface out of Model object class and try to implement it at the class holding Model as property?

 public interface IModel
    {
        public string UnitId { get; set; }
    }

    public class Model : IModel
    {
        private string unitId;
        public string UnitId
        {
            get { return unitId; }
            set { unitId = value; }
        }
    }

    public class ModelParent : IModel
    {
        private Model model;
        public string UnitId
        {
            get { return model.UnitId; }
            set { model.UnitId = value; }
        }
    }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top