I\'ve been searching for hours on this error that appears in the output window. I\'m pretty new to bindings in WPF, so I\'m sure there\'s something I\'m missing.
Ful
seems like you're binding your listviews itemssource to an object, not an array. is everything working visually? or do you see nothing?
EDIT: what happens if you write instead of:
<c:MyData x:Key="myDataSource"/>
this:
<x:Array x:Key="myDataSource" Type="{x:Type c:MyData}">
<c:MyData />
</x:Array>
or any likewise collection definition
You don't want to set the DataContext on the UserControl. Instead, you want to set it in the scope of the UserControl.
Usually you do this in the constructor of the UserControl. I usually add a line like this:
this.RootElement.DataContext = myData;
Where RootElement is the first sub-element (the Content) of your UserControl (usually a panel like Grid or StackPanel).
In your case it would be:
this.lsvwOutput.DataContext = FindResource("myDataSource")
;
And makes sure that it's after the InitializeComponent() call.
It's just a question of scoping. You set the datacontext on the root panel of the usercontrol. This is a really non-obvious part of WPF.
UPDATE: As Markus points out below, in the case of a listview, you want to set an array of data, not just a data point. Take that into consideration when setting the DataContext in your constructor.