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

それは、絵コンテはあるが、それをプレイしないからです。

そのストーリーボードを再生するトリガーを追加してみてください。このようなもの:

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

ところで、これはあなたのアニメーションの結果です:

ここに画像の説明を入力

于 2013-05-20T11:43:54.993 に答える
1

を開始する必要がありますStoryboard。あなたEventTriggerは何もしません。

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