首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >性质减法的ColorAnimation

性质减法的ColorAnimation
EN

Stack Overflow用户
提问于 2022-11-23 13:27:26
回答 1查看 28关注 0票数 0

如何使WPF通过属性从模板绑定的背景中减去?

我想使用"By“属性动画按钮模板的背景。如果我需要使背景变浅,它就能正确地工作,因为"By“加起来是”背景色“。但实际上,我想让它变得更暗,我不知道如何使WPF从模板绑定的背景中通过属性减去。

代码语言:javascript
复制
<Border x:Name="BackRect" Background="{TemplateBinding Background}" 
                CornerRadius="15" BorderThickness="0" Height="115" Width="215">
                <ContentControl x:Name="MainTitle"
                            FontFamily="Inter"    
                            FontSize="{TemplateBinding FontSize}" 
                            Content="{TemplateBinding Content}"
                            HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Border>

<ControlTemplate.Triggers>
            <EventTrigger RoutedEvent="MouseEnter">
                <BeginStoryboard>
                    <Storyboard> 
                        <ColorAnimation Storyboard.TargetName="BackRect" Storyboard.TargetProperty=(Button.Background).(SolidColorBrush.Color)"
                                        By="#A0A0A0" FillBehavior="HoldEnd" Duration="0:0:0.3" >
                            <ColorAnimation.EasingFunction>
                                <SineEase EasingMode="EaseOut"/>
                            </ColorAnimation.EasingFunction>
                        </ColorAnimation>
                    </Storyboard>
                </BeginStoryboard>
            </EventTrigger>
</ControlTemplate.Triggers>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-11-23 14:18:27

似乎,尽管在文档中显然没有提到,但是您可以对颜色结构的ScAScRScGScB属性使用负值,这样就可以通过颜色动画的By属性获得减去的颜色。

下面是一个示例:

代码语言:javascript
复制
<Rectangle Width="300" Height="200">
    <Rectangle.Fill>
        <SolidColorBrush Color="Red"/>
    </Rectangle.Fill>
    <Rectangle.Triggers>
        <EventTrigger RoutedEvent="MouseEnter">
            <BeginStoryboard Name="AnimateFillColor">
                <Storyboard>
                    <ColorAnimation
                        Storyboard.TargetProperty="Fill.Color"
                        Duration="0:0:0.2">
                        <ColorAnimation.By>
                            <Color ScR="-0.5"/>
                        </ColorAnimation.By>
                    </ColorAnimation>
                </Storyboard>
            </BeginStoryboard>
        </EventTrigger>
        <EventTrigger RoutedEvent="MouseLeave">
            <StopStoryboard BeginStoryboardName="AnimateFillColor"/>
        </EventTrigger>
    </Rectangle.Triggers>
</Rectangle>
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/74547548

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档