0

当鼠标悬停时,我想将按钮的大小从 70 更改为 90:

<Style TargetType="Button"
       x:Key="RadialButton">
  <Setter Property="Width"
          Value="70"></Setter>
  <Setter Property="Height"
          Value="85"></Setter>
  <Setter Property="Template">
    <Setter.Value>
      <ControlTemplate>
        <ControlTemplate.Resources>
          <Storyboard x:Key="Storyboard1">
            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Width)"
                                           Storyboard.TargetName="ExtEllipse">
              <EasingDoubleKeyFrame KeyTime="0:0:1"
                                    Value="90" />
            </DoubleAnimationUsingKeyFrames>
          </Storyboard>
        </ControlTemplate.Resources>
        <Grid Name="MainGrid">
          <Grid.RowDefinitions>
            <RowDefinition Height="70"></RowDefinition>
            <RowDefinition Height="15"></RowDefinition>
          </Grid.RowDefinitions>
          <Ellipse Width="70"
                   Height="70"
                   Stroke="Gray"
                   Grid.Row="0"
                   Name="ExtEllipse"
                   Fill="{x:Null}" />
          <Ellipse Width="50"
                   Height="50"
                   Stroke="Gray"
                   Grid.Row="0"></Ellipse>
          <TextBlock Grid.Row="1"
                     FontSize="13"
                     FontWeight="Bold"
                     TextAlignment="Center"
                     Foreground="Green">
                        <ContentPresenter RecognizesAccessKey="True"
                                          Content="{TemplateBinding Button.Content}" />
          </TextBlock>
        </Grid>
        <ControlTemplate.Triggers>
          <EventTrigger RoutedEvent="FrameworkElement.Loaded" />
        </ControlTemplate.Triggers>
      </ControlTemplate>
    </Setter.Value>
  </Setter>
</Style>  

使用:

<Button Content="Button"
        HorizontalAlignment="Left"
        Margin="36,140,0,147"
        Width="151"
        Style="{DynamicResource RadialButton}" />

但它不起作用。没啥事儿。为什么以及如何解决这个问题?

4

2 回答 2

1

你必须开始你的Storyboard. 你EventTrigger什么都不做。

<EventTrigger RoutedEvent="MouseEnter">
    <BeginStoryboard Storyboard="{StaticResource Storyboard1}" />
</EventTrigger>
于 2013-05-20T11:43:21.100 回答
1

那是因为你有 Storyboard,但你不玩它。

尝试添加触发器来播放该故事板。像这样的东西:

<Trigger Property="IsMouseOver" Value="True">
    <Trigger.EnterActions>
        <BeginStoryboard Storyboard="{StaticResource Storyboard1}" />
    </Trigger.EnterActions>
</Trigger>

顺便说一句,这是你的动画的结果:

在此处输入图像描述

于 2013-05-20T11:43:54.993 回答