开发者

EventTrigger on a TextBlock that sets a Border - Cannot resolve all property references

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.

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

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

Here is the code that causes trouble:

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

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

Thanks!

EDI开发者_Python百科T: 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" that changes to Storyboard.TargetProperty="Border.BorderBrush",

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


Try

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

but you have to declare a BorderBrush

BorderBrush="whatever"

or

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

in your "myborder" too.


On your ColorAnimation there are two properties:

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

It implies, that myborder has a property called Border. I think that causes your error.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜