设置边框的TextBlock上的EventTrigger-无法解析所有属性引用 [英] EventTrigger on a TextBlock that sets a Border - Cannot resolve all property references

查看:91
本文介绍了设置边框的TextBlock上的EventTrigger-无法解析所有属性引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在WPF中有一个自定义控件,在其中定义了一个较大的ItemsControl模板. 在其中,我有一个网格,在该网格的一列中,有一个TextBlock,在另一列中,有一个Border.

I have a Custom control in WPF in which I define a large ItemsControl Template. In there, I have a Grid and in one column of that grid, I got a TextBlock and in another column I have a Border.

当鼠标进入TextBlock时,我想突出显示边框.

I want to highlight the Border when the mouse enters the TextBlock.

我尝试了几种情况: 首先是TextBlock样式中的EventTrigger,但我了解到您无法做到这一点,然后是TextBlock的Triggers部分中的EventTrigger,现在我将其放置在ItemsControl的DataTemplate.Triggers中,但是我一直在获取错误:

I tried several scenarios: first an EventTrigger in the TextBlock's Style, but I learned that you can't do that, then an EventTrigger within the TextBlock's Triggers section, and now I just put it in the DataTemplate.Triggers of my ItemsControl, but I keep getting the error:

"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>

我认为我在提及边框的Color属性时缺少一些见解吗?

I think I'm missing something about the way i refer to the Color property of my Border, any insight?

谢谢!

编辑:我发现在Resources中声明SolidColorBrush然后使用该值可以使我摆脱

EDIT: I figured out that declaring a SolidColorBrush in Resources and then using that value allows me to get rid of the

Storyboard.TargetProperty="Border.BorderBrush.Color"更改为Storyboard.TargetProperty="Border.BorderBrush"

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

but now the compiler tells me that the color i declared (i tried Green and Transparent) is not a valid value for "To"...

推荐答案

尝试

<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"中.

in your "myborder" too.

这篇关于设置边框的TextBlock上的EventTrigger-无法解析所有属性引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆