2

When I bind something to the SelectedItem of a ListView using ElementName, the properties cannot be resolved.

I can still build and run my app, but because of this error I'm not sure that I didn't make any typo's.

I read and tried the answer given in ElementName Binding is failing but Source={x:Reference ...} doesn't seem to exist in the WinRT framework.

Just an example:

My page has a property MyContainerObject with an IEnumerable<MyParentObject> inside called MyParents. Each MyParentObject has an IEnumerable<MyChildObject> called MyChildren inside.

The DataContext of my page:

DataContext="{Binding RelativeSource={RelativeSource Self}}"

I have ListView with the following XAML properties:

  • x:Name = "FirstListView"
  • ItemsSource = {Binding MyContainerObject.MyParents}

Then I have another ListView with the following XAML properties:

  • x:Name = "SecondListView"
  • ItemsSource = "{Binding SelectedItem.MyChildren, ElementName=FirstListView}"

Now ReSharper gives me the following warning:

Cannot resolve property 'MyChildren' in data context of type 'object'.
Community
  • 1
  • 1
Sam Debruyn
  • 928
  • 1
  • 8
  • 22
  • Tried using an IValueConverter but the return type of Convert() is also object so that didn't work. https://twitter.com/WesleyCabus/status/491529341424390145 – Sam Debruyn Jul 22 '14 at 10:44

1 Answers1

2

Add this to your listview:

d:DataContext="{d:DesignInstance model:MyParentObject}"
Nico Vermeir
  • 160
  • 1
  • 7