0

1) 繰り返しボタンの表示状態は長方形で、押すと Stroke が透明から灰色に変わります。

この視覚的な状態の変化は、押されたときに 1 回だけ発生します。

これは繰り返しボタンなので、 を押している間、視覚状態の変化を繰り返し (押した点滅のように) 繰り返したいのですが、視覚状態を変更してそのような効果を得るにはどうすればよいですか?

<ControlTemplate TargetType="{x:Type RepeatButton}">
    <Grid>
      <VisualStateManager.VisualStateGroups>
        <VisualStateGroup x:Name="CommonStates">
            <VisualStateGroup.Transitions>
            <VisualTransition GeneratedDuration="0" To="Pressed"/>
            </VisualStateGroup.Transitions>
               <VisualState x:Name="Pressed">
                  <Storyboard>
                     <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Shape.Stroke).(SolidColorBrush.Color)" Storyboard.TargetName="rectangle">
                            <EasingColorKeyFrame KeyTime="0" Value="#FF8F8E8E" />
                    </ColorAnimationUsingKeyFrames>
                  </Storyboard>
               </VisualState>
        </VisualStateGroup>
     </VisualStateManager.VisualStateGroups>
    <Rectangle x:Name="rectangle" HorizontalAlignment="Stretch" Stroke="Transparent" Fill="Transparent" VerticalAlignment="Stretch" />                                                                      
    </Grid>                 
</ControlTemplate>

2)私が念頭に置いていた1つのアプローチは、クリックイベントのEventTriggerでGoToStateActionを使用することです(繰り返しボタンがそのイベントを何度も再起動するため)、

しかし、私は GoToStateAction を ControlTemplate に直接配置することはできないようです。

結論として、iv'eには2つの問題があります:

1) この問題を解決する一般的な考え方。

2) 私の考えでは、GoToStateAction を ControlTemplate オブジェクトに配置する必要があります。これは実行できないようです。これを回避する方法はありますか?

前もって感謝します。

4

1 に答える 1

1

Visual States の代わりに Triggers を使用してみてください

<ControlTemplate TargetType="{x:Type RepeatButton}">
                            <ControlTemplate.Resources>
                                <Storyboard x:Key="repeatSb" AutoReverse="True" RepeatBehavior="Forever">
                                        <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Shape.Stroke).(SolidColorBrush.Color)" Storyboard.TargetName="rectangle">
                                        <EasingColorKeyFrame KeyTime="0" Value="Red"   />
                                        <EasingColorKeyFrame KeyTime="0:0:0.5" Value="Transparent"/>
                                </ColorAnimationUsingKeyFrames>
                                </Storyboard>
                            </ControlTemplate.Resources>
                                <Grid>
                                 <Rectangle x:Name="rectangle" HorizontalAlignment="Stretch" 
                                       Stroke="Transparent" Fill="#FFFBD0D0" VerticalAlignment="Stretch" />                                                                      
                               </Grid>
                            <ControlTemplate.Triggers>
                                <Trigger Property="IsPressed" Value="True">
                                    <Trigger.EnterActions>
                                        <BeginStoryboard x:Name="repeatSb_BeginStoryboard" 
                                        Storyboard="{StaticResource repeatSb}"/>
                                    </Trigger.EnterActions>
                                </Trigger>
                                <Trigger Property="IsPressed" Value="False">
                                    <Trigger.EnterActions>
                                        <StopStoryboard BeginStoryboardName="repeatSb_BeginStoryboard"/>
                                    </Trigger.EnterActions>
                                </Trigger>
                            </ControlTemplate.Triggers>
                        </ControlTemplate>
于 2013-08-12T03:37:11.813 に答える