【问题标题】:WPF: add blur effect on button when mouse is on that button-MouseEnterWPF:当鼠标在该按钮上时,在按钮上添加模糊效果-MouseEnter
【发布时间】:2023-03-13 06:50:02
【问题描述】:

我正在尝试制作一个简单的动画 - 当鼠标光标位于按钮上时,我想在该按钮上添加模糊效果。

到目前为止,我有这个。:

<Button x:Name="button_Copy" Content="Leaderboard" HorizontalAlignment="Left" Margin="311,217,0,0"  VerticalAlignment="Top" Width="139" Height="34" Background="{x:Null}" BorderBrush="{x:Null}" FontSize="22" FontWeight="Bold" Foreground="#FFE2DBDB" IsHitTestVisible="True" Click="button_Copy_Click">    
    <Button.Triggers>
        <EventTrigger RoutedEvent="MouseEnter">
             <BeginStoryboard>
                 <Storyboard>    
                     <DoubleAnimation From="10" To="0" Duration="0:0:0.1" 
                                Storyboard.TargetName="blurEffect" Storyboard.TargetProperty="Radius"/>    
                 </Storyboard>
             </BeginStoryboard>
         </EventTrigger>
     </Button.Triggers>                
 </Button>   

构建成功,但是当我将光标移到该按钮上时程序立即崩溃...知道如何解决这个问题吗?

【问题讨论】:

  • 我们在这里缺少blurEffect 定义

标签: c# wpf xaml


【解决方案1】:

我知道你可能从 here 中获取了你的例子。

您缺少对象BlurEffect,如下图TextBox 项目中所示:

<TextBlock Name="TxtSample" TextAlignment="Center" VerticalAlignment="Center" HorizontalAlignment="Center" Text="This is a sample and first test freetext">
    <TextBlock.Effect>
        <BlurEffect Radius="10" x:Name="blurEffect"/>
    </TextBlock.Effect>
</TextBlock>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-15
    • 1970-01-01
    • 2011-06-30
    • 2013-01-17
    • 1970-01-01
    相关资源
    最近更新 更多