2010-10-13 124 views
1

我什至不知道如何表达这一点,所以即时通讯非常抱歉,如果标题是混乱。我的XAML(简体)看起来是这样的:绑定在一个曾孙上的属性,以祖先

<UserControl x:Class="PBA.Application.Client.UserControls.UserControls.FreqReserve.OverView" xmlns:FreqReserve="clr-namespace:PBA.Application.Client.UserControls.UserControls.FreqReserve"> 
... 
    <DockPanel> 
     <UserControls:LegendControl> 
      <UserControls:LegendControl.Items> 
       <UserControls:LegendItem Visibility="{Binding Path=IsDirtyVisible, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type FreqReserve:OverView}}, Converter={StaticResource btvc}}" Identifier="Pink" Text="Ikke sendt"></UserControls:LegendItem> 
       <UserControls:LegendItem Identifier="Yellow" Text="Sendt"></UserControls:LegendItem> 
       <UserControls:LegendItem Identifier="LightGreen" Text="Accepteret"></UserControls:LegendItem> 
       <UserControls:LegendItem Identifier="White" Text="Ikke accepteret"></UserControls:LegendItem> 
      </UserControls:LegendControl.Items> 
     </UserControls:LegendControl> 
    </DockPanel> 
</UserControl> 

其中LegendItem列表模板化在legendcontrol中。

绑定表达式失败,出现System.Windows.Data错误:4.我尝试过使用elementname,而使用相同的结果。我猜这与LegendItems有些关系,并不直接在Visual树中,但我不知道(WPF菜鸟,我知道)。我究竟做错了什么?

回答

1

您在AncestorType中有错字。你想说FreqReserve.OverView。此外,您将不得不引用UserControl中定义的库的名称空间。

事情是这样的:

<UserControl x:Class="PBA.Application.Client.UserControls.UserControls.FreqReserve.OverView" 
      ... 
      xmlns:local="clr-namespace:PBA.Application.Client.UserControls.UserControls"> 

    ... 
     <DockPanel> 
     <UserControls:LegendControl> 
      <UserControls:LegendControl.Items> 
       <UserControls:LegendItem IsVisible="{Binding Path=IsDirtyVisible, 
        RelativeSource={RelativeSource Mode=FindAncestor, 
            AncestorType={x:Type local:FreqReserve.OverView}}}" 
        Identifier="Pink" 
        Text="Ikke sendt"></UserControls:LegendItem> 

       ....   

     </UserControls:LegendControl> 
    </DockPanel> 
</UserControl> 

请注意,您必须把正确的命名空间为“本地”的声明,但你应该从智能感知,如果你不知道它应该是什么。

+0

对不起。在去除绒毛的时候稍微过了一会儿,并且用手写了一段代码,因为它不再是实际的代码。代码段已更新以更好地反映实际代码。 – hhravn 2010-10-13 13:51:30

+0

让我们从简单的开始,并努力解决问题。 IsDirtyVisible是OverView控件的属性吗? – 2010-10-13 14:14:45

+0

是的,它是一个包装的依赖属性。 – hhravn 2010-10-13 14:47:51