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
385
unbound field 3 levels deep into the View Model - Binding issue
posted

I was trying to bind the grid to a data model where the hierarchy  is 3 levels deep: 

In the example code: I want to bind the grid to : ValueInnerInner, but this does not work.

 

 

public class ViewModel

    {

        public ViewModel()

        {

            DataSource = new ObservableCollection<SomeModel>();

            DataSource.Add(new SomeModel());

 

        }

 

        public ObservableCollection<SomeModel> DataSource

        {

            get;

            private set;

        } 

    } 

 

    public class SomeModel

    {

        public SomeModelInner Inner

        {

            get;

            set; 

        } 

 

        public SomeModel()

        {

            Inner = new SomeModelInner();

        }

    }

 

    public class SomeModelInner

    {

        public int Value

        {

            get

            {

                return 200;

            }

        } 

 

        public SomeModelInnerInner InnerInner

        {

            get;

            set;

        } 

 

        public SomeModelInner()

        {

 

        }

    }

 

    public class SomeModelInnerInner

    {

        public int ValueInnerInner

        {

            get

            {

                return 200;

            } 

        } 

 

        public SomeModelInnerInner()

        {

 

        }

    }


  • 95
    posted

    Here are the things that have hung me up working with databinding:

    Always make sure your Classes in the viewmodel have the interface : INotifiyPropertyChanged

    Always make sure the classes that you are binding to are public,

    Always make sure the Variables that you are binding to are public,

    Always make sure you are calling the INotifyPropertyChanged Event

    Always make sure all of the classes in a large heirarchy binding are initialized.

     

    It doesn't look like SomeModelInnerInner is getting initialized:

    Also you are not using INotifyPropertyChanged, this may be causing problems also

    eg:

    public class SomeModelInner

        {

            public int Value

            {

                get

                {

                    return 200;

                }

            } 

     

            public SomeModelInnerInner InnerInner

            {

                get;

                set;

            } 

     

            public SomeModelInner()

            {

                 InnerInner = new SomeModelInnerInner();

            }

        }

     

     hope this helps,

    Chad

  • 385
    posted

     

     

     

     

     

     

     

     

     

     

     

     

     

    here is the layout value for the above problem:

    <

     

     

    ig:XamDataGrid.FieldLayouts

    >

     

     

     

    <ig:FieldLayout Key

    ="XamGridLayout">

     

     

     

    <ig:UnboundField

     

     

    Name="Value"

     

     

    Label="Inner Value"

     

     

    BindingPath

    ="Inner.Value"

     

     

     

    />

     

     

     

     

    <ig:UnboundField

     

     

    Name="ValueInnerInner"

     

     

    Label="Inner Inner Value"

     

     

    BindingPath

    ="Inner.InnerInner.ValueInnerInner"

     

     

     

    />

     

     

     

    </ig:FieldLayout

    >

     

     

     

     

    </ig:XamDataGrid.FieldLayouts

    >