<Window x:Class="TestUserControlBinding.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:system="clr-namespace:System;assembly=mscorlib"
xmlns:local="clr-namespace:TestUserControlBinding"
Title="MainWindow" Height="350" Width="525">
<Grid>
<ListView>
<ListView.ItemTemplate>
<DataTemplate>
<!--<Label Content="{Binding IsSelected, RelativeSource={RelativeSource FindAncestor, AncestorType=ListViewItem}}" />-->
<local:MyUserControl Content="{Binding IsSelected, RelativeSource={RelativeSource FindAncestor, AncestorType=ListViewItem}}" />
</DataTemplate>
</ListView.ItemTemplate>
<ListView.Items>
<system:String>First</system:String>
<system:String>Second</system:String>
<system:String>Third</system:String>
</ListView.Items>
</ListView>
</Grid>
</Window>
注释的标签行正常工作(如果在ListView中选中,则显示True,否则显示False)。
系统.Windows.Data错误:40:
在上找不到“Content”属性
'对象'''字符串'
(HashCode=-1920739956)'。
装订xpression:路径=内容;
DataItem='String'
(HashCode=-1920739956);目标元素
是“Content”(类型为“Object”)
MyUserControl只包含绑定到Content属性的标签:
<Grid>
<Label Content="{Binding Content}" />
</Grid>
有人知道为什么UserControl的行为不同于Label控件吗?(或者至少能帮我看看我明显遗漏了什么?)