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
set;
public SomeModel()
Inner = new SomeModelInner();
public class SomeModelInner
public int Value
get
return 200;
public SomeModelInnerInner InnerInner
public SomeModelInner()
public class SomeModelInnerInner
public int ValueInnerInner
public SomeModelInnerInner()
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:
InnerInner = new SomeModelInnerInner();
hope this helps,
Chad
Hello,
You can create such binding path and this is valid. Do you get any exceptions in the output window?
I am attaching the sample I created for this so you can look at it for reference.
here is the layout value for the above problem:
<
>
="XamGridLayout">
="Inner.Value"
/>
="Inner.InnerInner.ValueInnerInner"