我输出错误
System.Windows.Data Error: 4 : Cannot find source for binding with
reference 'RelativeSource FindAncestor,
AncestorType='System.Windows.Controls.ContentControl',
AncestorLevel='1''. BindingExpression:Path=Background; DataItem=null;
target element is 'Path' (Name=''); target property is 'Fill' (type
'Brush')
但是,就路径显示而言,一切都没问题。我得到了很多这样的错误,它们很烦人,但一切都按预期工作,这里是xaml
<DataTemplate x:Key="CheckboxListDataTemplate">
<ContentControl Width="30"
Height="30"
Background="Black"
IsTabStop="False">
<ContentControl.Style>
<Style TargetType="ContentControl">
<Style.Triggers>
<Setter Property="Content" Value="{StaticResource CompoundedViewbox}" />
</DataTrigger>
</Style.Triggers>
</Style>
</ContentControl.Style>
</ContentControl>
</DataTemplate>
<Viewbox x:Key="CompoundedViewbox" x:Shared="False">
<Grid>
<Path Data="F1 M 28.437,30.470 C 28.187,30.586 27.908,30.644 " Fill="{Binding Path=Background, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ContentControl}}" />
<Path Data="F1 M 24.917,35.717 C Z" Fill="{Binding Path=Background, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ContentControl}}" />
</Grid>
</Viewbox>
当我更改内容控件中的背景时,视图框会随时更改颜色,但它会显示输出错误,它无法找到它。
任何想法为什么会发生?
聚苯乙烯。我删除了大部分路径数据,因为它太长了。
亲切的问候