2

ボタンが押されたときのアニメーションは必要ありませんが、メトロ スタイルのように前景と背景のみが変更されます。私はとても困惑しています。

編集:

Expression Blend 4 でサンプルを作成します。Normal、IsMouseOver、IsPressed の 3 つの状態があります。 ここに画像の説明を入力

編集2:

「WPF: ボタンが押されたときにアニメーションを無効にする方法は?」というタイトルを変更するだけです。「WPFで:ボタンが押されたときにアニメーションを無効にする方法は?」

私はいくつかの問題を見つけました:

  1. マウスが上にあるとき、またはボタンを押したときに、ボタンの背景は変更されません。
  2. ボタンが押された後にアニメーションが実行されます。アニメーションを無効にしたいだけです。

編集3:

この .xaml は 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>

4

1 に答える 1

2

これを試してください(新しいプロジェクトを作成し、定義の下に貼り付けてください):

<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>
于 2013-10-12T06:06:31.870 に答える