2
votes

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'.
1
Tried using an IValueConverter but the return type of Convert() is also object so that didn't work. twitter.com/WesleyCabus/status/491529341424390145 - Sam Debruyn

1 Answers

2
votes

Add this to your listview:

d:DataContext="{d:DesignInstance model:MyParentObject}"