徽章控件徽章尺寸

时间:2018-03-26 12:27:02

标签: wpf xaml mahapps.metro

我想尝试使用Mahapps的徽章控制。是否可以更改徽章的大小(而不仅仅是颜色/值/等..) 最后我试图在徽章值改变时做一些更大的脉冲效果,我尝试了下面的颜色,但它不起作用:

                 <Controls:Badged.Triggers>
                        <EventTrigger RoutedEvent="Controls:Badged.BadgeChanged">
                            <EventTrigger.EnterActions>
                                <BeginStoryboard Name="AnimateVisibilityChanged">
                                    <Storyboard>
                                        <ColorAnimation Duration="0:0:0.5"
                                                        From="#FFEE4709"
                                                        To="Green"
                                                        BeginTime="0:0:0"
                                                        Storyboard.TargetProperty="(Controls:Badged.BadgeBackground).(SolidColorBrush.Color)">
                                        </ColorAnimation>
                                        <ColorAnimation Duration="0:0:0.5"
                                                        From="Green"
                                                        To="Transparent"
                                                        AutoReverse="True"
                                                        BeginTime="0:0:2"
                                                        RepeatBehavior="0:0:2.5"
                                                        Storyboard.TargetProperty="(Controls:Badged.BadgeBackground).(SolidColorBrush.Color)">
                                        </ColorAnimation>
                                    </Storyboard>
                                </BeginStoryboard>
                            </EventTrigger.EnterActions>
                            <EventTrigger.ExitActions>
                                <RemoveStoryboard BeginStoryboardName="AnimateVisibilityChanged" />
                            </EventTrigger.ExitActions>
                        </EventTrigger>
                    </Controls:Badged.Triggers> 

如果这样做的话,下一步就是增加尺寸而不是增加

1 个答案:

答案 0 :(得分:1)

看起来我会回答我的问题:

  • 动画没有用,因为我使用的是EnterActions而不是简单的动作(EventTrigger.Actions)
  • 要在值更改时更改徽章的大小,我必须使用BadgeChangedStoryboard属性并替换为我自己的:

    <SineEase x:Key="BadgeEase"
              EasingMode="EaseOut" />
    <Storyboard x:Key="BadgeChangedStoryboard">
        <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(ScaleTransform.ScaleX)">
            <EasingDoubleKeyFrame KeyTime="0"
                                  Value="2.3" />
            <EasingDoubleKeyFrame EasingFunction="{StaticResource BadgeEase}"
                                  KeyTime="0:0:0.3"
                                  Value="1" />
        </DoubleAnimationUsingKeyFrames>
        <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(ScaleTransform.ScaleY)">
            <EasingDoubleKeyFrame KeyTime="0"
                                  Value="2.3" />
            <EasingDoubleKeyFrame EasingFunction="{StaticResource BadgeEase}"
                                  KeyTime="0:0:0.3"
                                  Value="1" />
        </DoubleAnimationUsingKeyFrames>
    </Storyboard>
    

要更改大小,请同时更改缓动双键框值