在WPF:如何禁用动画当按钮后pressed? [英] In WPF: how to disable the animation when the button after be pressed?

查看:192
本文介绍了在WPF:如何禁用动画当按钮后pressed?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想没有动画时,按钮pressed,但只有前景和背景被改变的,就像Metro风格。我很困惑。

I want no animation when button is pressed, but only the foreground and the background are changed, just like metro style. I'm so perplexed.

编辑:

我创建防爆pression混合4样本。
有3种状态:正常,IsMouseOver是pressed:

I create a sample in Expression Blend 4. There are 3 states: Normal, IsMouseOver, IsPressed:

编辑2:

我只需要修改的标题是在WPF:如何禁用动画时,按钮pssed $ P $以在WPF:如何禁用动画当按钮后pssed $ P $

I just modify the Title "In WPF: how to disable the animation when the button is pressed?" to "In WPF: how to disable the animation when the button after be pressed?"

我发现一些问题:


  1. 当鼠标悬停或preSS按钮,按钮的研究背景没有改变;

  2. 按钮后的动画运行已是pressed,我只是想禁用动画。

修改3:

本的.xaml可在VS运行。

This .xaml can run in VS.

<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="WpfApplication17.MainWindow"
x:Name="Window"
Title="MainWindow"
Width="640" Height="480">
<Window.Resources>
    <Style x:Key="ButtonStyle1" TargetType="{x:Type Button}">
        <Style.Triggers>
            <Trigger Property="IsMouseOver" Value="True">
                <Setter Property="Foreground" Value="White"/>
                <Setter Property="BorderBrush" Value="Black"/>
                <Setter Property="Background" Value="Black"/>
            </Trigger>
            <Trigger Property="IsPressed" Value="True">
                <Setter Property="Background" Value="Black"/>
                <Setter Property="BorderBrush" Value="Black"/>
                <Setter Property="Foreground" Value="Red"/>
            </Trigger>
        </Style.Triggers>
        <Setter Property="Background" Value="White"/>
        <Setter Property="BorderBrush" Value="White"/>
        <Setter Property="Foreground" Value="Black" />
        <Setter Property="BorderThickness" Value="1"/>
        <Setter Property="HorizontalContentAlignment" Value="Center"/>
        <Setter Property="VerticalContentAlignment" Value="Center"/>
        <Setter Property="Padding" Value="1"/>
    </Style>

</Window.Resources>

<Grid x:Name="LayoutRoot" >
    <Button Content="Button" 
            HorizontalAlignment="Left" 
            VerticalAlignment="Top" 
            Width="75" 
            Style="{DynamicResource ButtonStyle1}"/>
</Grid>

推荐答案

试试这个(创建一个新的项目,只需将其粘贴定义下):

Try this (create a new project and just paste it beneath your definition) :

<Window.Resources>
        <Style x:Key="NoAnimations" TargetType="{x:Type Button}" >
            <Setter Property="Foreground" Value="Black" />
            <Setter Property="Background" Value="White"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="Button">
                        <Border BorderBrush="Black" BorderThickness="1">
                            <Border Name="border" Background="{TemplateBinding Background}" Padding="3">
                                <Grid>
                                    <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" Name="content" />
                                </Grid>
                            </Border>
                        </Border>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsMouseOver" Value="True">
                               <Setter Property="Background" Value="Black"></Setter>
                                <Setter Property="Foreground" Value="White"></Setter>
                            </Trigger>
                            <Trigger Property="IsMouseOver" Value="False">
                                <Setter Property="Background" Value="White"></Setter>
                                <Setter Property="Foreground" Value="Black"></Setter>
                            </Trigger>
                            <Trigger Property="IsPressed" Value="True">
                                <Setter Property="Background" Value="Black"></Setter>
                                <Setter Property="Foreground" Value="Red"></Setter>
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </Window.Resources>

    <StackPanel>
        <Button Style="{StaticResource NoAnimations}"
                Content="Testing"
                HorizontalAlignment="Center"
                VerticalAlignment="Center"
                Margin="20"

                />
    </StackPanel>

这篇关于在WPF:如何禁用动画当按钮后pressed?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆