Silverlight 4 Front Color

I am trying to animate a hyperlink foreground color when a MouseOver user controls. I created my own style in which I want to animate the foreground color. Foreground color set this way

<Setter Property="Foreground" Value="#FF73A9D8"/>

In the visualStateManager section, I have the following item for color animation

<ColorAnimation Duration="0:0:0.5" 
              Storyboard.TargetName="contentPresenter" 
              Storyboard.TargetProperty="(Control.Foreground).(SolidColorBrush.Color)" 
              To="Black" />

The problem is that I cannot figure out what the value of Storyboard.TargetName should be.

The text is set in a ContentPresenter control that does not have a Foreground property.

+3
source share
1 answer

You're right. Cannot hang animation inside control template.

HyperlinkButton , , .

, 2 MouseEnter/MouseLeave ( "XAML GlowingHyperlinkButton" ). , :

<UserControl
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"
    mc:Ignorable="d"
    x:Class="SilverlightApplication1.GlowingHyperlinkButton"
    d:DesignWidth="94" d:DesignHeight="16">
    <UserControl.Resources>
        <Storyboard x:Name="MouseEnterStoryboard">
            <ColorAnimation Duration="0:0:0.5" To="#FFDF00EB" Storyboard.TargetProperty="(Control.Foreground).(SolidColorBrush.Color)" Storyboard.TargetName="hyperlinkButton" d:IsOptimized="True"/>
        </Storyboard>
        <Storyboard x:Name="MouseLeaveStoryboard">
            <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Control.Foreground).(SolidColorBrush.Color)" Storyboard.TargetName="hyperlinkButton">
                <SplineColorKeyFrame KeyTime="0:0:0.5" Value="#FF49ED28"/>
            </ColorAnimationUsingKeyFrames>
        </Storyboard>
    </UserControl.Resources>

    <Grid x:Name="LayoutRoot">
        <HyperlinkButton x:Name="hyperlinkButton" Content="HyperlinkButton" Foreground="#FF49ED28" d:LayoutOverrides="Width, Height">
            <i:Interaction.Triggers>
                <i:EventTrigger EventName="MouseEnter">
                    <ei:ControlStoryboardAction Storyboard="{StaticResource MouseEnterStoryboard}"/>
                </i:EventTrigger>
                <i:EventTrigger EventName="MouseLeave">
                    <ei:ControlStoryboardAction Storyboard="{StaticResource MouseLeaveStoryboard}"/>
                </i:EventTrigger>
            </i:Interaction.Triggers>
        </HyperlinkButton>
    </Grid>
</UserControl>

. , :)

+4

Source: https://habr.com/ru/post/1761047/


All Articles