2013-06-18 3 views
1

Я не хочу анимации при нажатии кнопки, но меняются только передний план и фон, так же, как стиль метро. Я так озадачен.В WPF: как отключить анимацию при нажатии кнопки после нажатия?

Edit:

создать образец в Expression Blend 4. Есть 3: Нормальный, IsMouseOver, IsPressed: enter image description here

Edit 2:

Я просто изменить заголовок «В WPF: как отключить анимацию при нажатии кнопки»? на «В WPF: как отключить анимацию при нажатии кнопки?»

Я нахожу некоторые проблемы:

  1. При наведении курсора мыши или нажать на кнопку, то Backgroud кнопки не изменились;
  2. Анимационный запуск после нажатия кнопки, я просто хочу отключить анимацию.

Edit 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> 

+0

ли вы рассмотреть вопрос об изменении [Style] (http://msdn.microsoft. ru/en-us/library/ms753328.aspx) кнопки? – Clemens

+0

Что вы попробовали? Пожалуйста, поделитесь своим XAML. –

+0

@Clemens да, я пытаюсь. – SubmarineX

ответ

1

Попробуйте это (создать новый проект и просто вставить его под ваше определение):

<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> 
Смежные вопросы