2011-08-10 32 views
4

我在WPF中定义了一个大的ItemsControl模板的自定义控件。 在那里,我有一个网格,并在该网格的一列中,我得到了一个TextBlock,在另一列中我有一个边框。设置边框的TextBlock上的EventTrigger - 无法解析所有属性引用

我想在鼠标进入TextBlock时突出显示边框。

我尝试了几种方案:第一 TextBlock中的风格的EventTrigger,但我知道,你不能将TextBlock的触发区间内做到这一点,那么一个EventTrigger,现在我只要把它的DataTemplate.Triggers我的ItemsControl,但我不断收到错误:

"Cannot resolve all property references in the property path 'Border.BorderBrush.Color'. Verify that applicable objects support the properties." 

下面是导致代码的麻烦:

<DataTemplate.Triggers> 
    <EventTrigger SourceName="mytxtblock" RoutedEvent="TextBlock.MouseEnter"> 
     <EventTrigger.Actions> 
      <BeginStoryboard> 
       <Storyboard> 
        <ColorAnimation Storyboard.TargetName="myborder" 
               Storyboard.TargetProperty="Border.BorderBrush.Color" 
               Duration="0:0:1"                   
               To="White" /> 
        <ThicknessAnimation Storyboard.TargetProperty="Border.BorderThickness" 
                Duration="0:0:1" 
                From="0" 
                To="1" /> 
       </Storyboard> 
      </BeginStoryboard> 
     </EventTrigger.Actions> 
    </EventTrigger> 
</DataTemplate.Triggers> 

我想我失去了一些东西约我指的颜色属性的方式我BORD呃,有什么见解?

谢谢!

编辑:我想通了,宣布在Resources一个SolidColorBrush,然后使用该值可以让我摆脱

Storyboard.TargetProperty="Border.BorderBrush.Color"改变到Storyboard.TargetProperty="Border.BorderBrush"

但现在的编译器告诉我,我声明的颜色(我试过绿色和透明)不是“有效”值...

回答

4

尝试

<ColorAnimation 
    Storyboard.TargetName="myborder" 
    Storyboard.TargetProperty="BorderBrush.(SolidColorBrush.Color)" 
    Duration="0:0:1" 
    To="White" /> 

,但你必须声明BorderBrush

BorderBrush="whatever" 

<Border.BorderBrush> 
    <SolidColorBrush Color="whatever" /> 
</Border.BorderBrush> 

在 “myborder” 了。

+0

我收到一个异常:'BorderBrush'属性不指向路径'BorderBrush。(0)'中的DependencyObject。 –

+0

我编辑了我的答案。 – LPL

+0

我可能永远不会得到WPF绑定路径的萦绕,但“BorderBrush(SolidColorBrush.Color)”为我的UserControl边框工作,所以谢谢! – Jon

0

在您的ColorAnimation有两个属性:

Storyboard.TargetName="myborder" 
Storyboard.TargetProperty="Border.BorderBrush.Color" 

这意味着,该myborder有一个名为Border属性。我认为这会导致你的错误。

相关问题