繁体   English   中英

如何使 WPF 按钮振动?

[英]How to make a WPF button vibrate?

我正在构建一个包含多个按钮的 Windows WPF 应用程序。 我想通知用户他应该加载 pdf 在他可以按下其他按钮之前通过使加载 pdf 按钮闪烁/振动如果用户点击其他地方并且没有加载 Z437175BA4191210EE004E1D9374。

例如 - 如果您尝试在打开的编辑 colors 框之外单击任何位置,则会在 Microsoft Paint 上发生确切的行为。 (见附图)

有人有想法吗?

在此处输入图像描述

您可以将 storyboard 与DoubleAnimation一起使用,更改阴影,使其自动返回 go 并重复(此处为 4 次)。

这是一个UserControl ,您可以将其重用于具有这种效果的所有按钮; 您只需将文本“按钮内容”替换为一些DependencyProperty即可使其具有通用性。

<UserControl x:Class="AnimateDropShadow"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
      xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
      mc:Ignorable="d">
    <Grid>
        <Button HorizontalAlignment="Left" >
            Button content
            <Button.Effect>
                <DropShadowEffect x:Name="warningEffect" Color="Black" BlurRadius="10"  ShadowDepth="0"/>
            </Button.Effect>
            <Button.Triggers>
                <EventTrigger RoutedEvent="Button.Click">
                    <BeginStoryboard>
                        <Storyboard>
                            <DoubleAnimation
                                Storyboard.TargetName="warningEffect"
                                Storyboard.TargetProperty="BlurRadius"
                                From="15" To="10" Duration="0:0:0.1"
                                AutoReverse="True" RepeatBehavior="0:0:0.4" />
                        </Storyboard>
                    </BeginStoryboard>
                </EventTrigger>
            </Button.Triggers>
        </Button>
    </Grid>
</UserControl>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM