【问题标题】:Animate a ToggleButton in Windows Phone 8.1在 Windows Phone 8.1 中为 ToggleButton 设置动画
【发布时间】:2015-06-15 16:47:22
【问题描述】:

我正在开发一个 Windows Phone 8.1(非 SilverLight)应用程序,其中有一个非常简单的 XAML 页面。

<Grid>
    <ToggleButton x:Name="TogBtn" VerticalAlignment="Center" HorizontalAlignment="Center" Checked="ToggleButton_OnChecked" Unchecked="TogBtn_OnUnchecked">Off</ToggleButton>
</Grid>

目前,ToggleButton 按预期工作,当检查其背景更改为设置的强调色时。

如何向它添加动画,以便在单击时,蓝色背景颜色缓和。

【问题讨论】:

  • 简单易行。首先提取样式模板右键单击编辑模板,或者如果您希望它们都具有相同的行为,则只需获取默认模板并将其粘贴到此处。在情节提要中添加持续时间或在 VisualStateManager 中的 VisualTransitions 中添加缓动应该按照您想要的方式对您进行排序。

标签: xaml animation windows-phone-8.1


【解决方案1】:

感谢 Chris 和 2 小时的谷歌搜索和玩弄它,我想通了:

<VisualState x:Name="Checked">
    <Storyboard>
        <ColorAnimation Duration="0:0:0.15" Storyboard.TargetName="Border" Storyboard.TargetProperty="(Background).(SolidColorBrush.Color)" To="Red"></ColorAnimation>
        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="Border"
            Storyboard.TargetProperty="BorderBrush">
            <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource ToggleButtonCheckedBorderThemeBrush}" />
        </ObjectAnimationUsingKeyFrames>
        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter"
            Storyboard.TargetProperty="Foreground">
            <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource ToggleButtonCheckedForegroundThemeBrush}" />
        </ObjectAnimationUsingKeyFrames>
    </Storyboard>
</VisualState>

花了很长时间才到达Storyboard.TargetProperty="(Background).(SolidColorBrush.Color)",否则它将无法正常工作。

获取full template here,然后如上所示更改&lt;VisualState x:Name="Checked"&gt;

谢谢

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-06-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-25
    相关资源
    最近更新 更多