【发布时间】:2010-08-10 12:50:15
【问题描述】:
我正在尝试显示笔记列表。我有一个绑定到 NoteViewModel 集合的 ItemsControl。所以在项目控件的数据模板中,我想创建一个 NoteControl(用于显示注释的用户控件)并将其 ViewModel 属性绑定到集合中的 NoteViewModel。
我目前有这个:
<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>
但我遇到了这个异常:
System.ArgumentException: Object of type 'System.Windows.Data.Binding' cannot be converted to type 'NotePrototype.NoteViewModel'.
将其连接起来的正确语法是什么?是否有更好的技术将内部 ViewModel 连接到动态创建/绑定的内部 UserControl?
【问题讨论】:
标签: silverlight silverlight-4.0