个人资料

跳过导航链接首页 > 博客列表 > 博客正文

Xaml使用style定义trigger进行Foreground颜色渐变

:

在style中定义ColorAnimation

            <Style x:Key="MyTextBlockStyle" TargetType="{x:Type TextBlock}">
                <Setter Property="TextWrapping" Value="NoWrap" />
                <Setter Property="TextTrimming" Value="None" />

                <Setter Property="FontSize" Value="16" />
                <Setter Property="Foreground" Value="Orange" />
                <Setter Property="FontFamily" Value="SongT" />
                <Style.Triggers>

                    <EventTrigger RoutedEvent="TextBlock.MouseEnter">
                        <BeginStoryboard>
                            <Storyboard Storyboard.TargetProperty="(TextBlock.Foreground).(SolidColorBrush.Color)">
                                <ColorAnimation From="Orange" To="DodgerBlue" Duration="0:0:0.1"></ColorAnimation>
                            </Storyboard>
                        </BeginStoryboard>

                    </EventTrigger>

                    <EventTrigger RoutedEvent="TextBlock.MouseLeave">
                        <BeginStoryboard>
                            <Storyboard Storyboard.TargetProperty="(TextBlock.Foreground).(SolidColorBrush.Color)">
                                <ColorAnimation From="DodgerBlue" To="Orange" Duration="0:0:0.1"></ColorAnimation>
                            </Storyboard>
                        </BeginStoryboard>

                    </EventTrigger>

                </Style.Triggers>
            </Style>


添加到App资源或者页面资源中,并且引用

songshizhao
最初发表2018/10/10 22:42:34 最近更新2018/10/10 22:42:34 4209
为此篇作品打分
10