I'm trying to display a list of Notes. I have an ItemsControl which is bound to a collection of NoteViewModel. So in the data template of the items control I want to create a NoteControl (user control for displaying a note) and bind its ViewModel property to the NoteViewModel in the collection.
I currently have this:
<ItemsControl x:Name="itemsControl1" Grid.Row="1" ItemsSource="{Binding Notes}" >
<ItemsControl.Template>
<ControlTemplate TargetType="ItemsControl">
<ScrollViewer>
<ItemsPresenter/>
</ScrollViewer>
</ControlTemplate>
</ItemsControl.Template>
<ItemsControl.ItemTemplate>
<DataTemplate>
<uc:NoteControl uc:NoteControl.ViewModel="{Binding}"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
But I'm getting this exception:
System.ArgumentException: Object of type 'System.Windows.Data.Binding' cannot be converted to type 'NotePrototype.NoteViewModel'.
What is the proper syntax for wiring this up? Is there a better technique for wiring up inner ViewModels to inner UserControls that are dynamically created/bound?