2017-04-22 3 views
0

私はボタンがあります。Viewのイベントでストーリーボードをトリガーする方法はありますか?

<Button x:Name="button" Click="{x:Bind ViewModel.OnButtonClick}"> 
     <Button.Projection> 
      <PlaneProjection RotationZ="50"/> 
     </Button.Projection> 
     <Button.Triggers> 
      <EventTrigger> 
       <BeginStoryboard> 
        <Storyboard x:Name="Storyboard1"> 
         <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Projection).(PlaneProjection.RotationZ)" Storyboard.TargetName="button"> 
          <EasingDoubleKeyFrame KeyTime="0" Value="50"/> 
          <EasingDoubleKeyFrame KeyTime="0:0:2" Value="320"/> 
         </DoubleAnimationUsingKeyFrames> 
        </Storyboard> 
       </BeginStoryboard> 
      </EventTrigger> 
     </Button.Triggers> 
    </Button> 

をボタンをクリックした後、メソッドが呼び出されるように、私はMVVMパターンを使用します。私もストーリーボードを開始したいのですが、私はViewModelのStoryboardを参照できないのでMVVMパターンのこのソリューションしか見つかりませんでした。

このストーリーボードを変更してボタンクリックでのみ起動する方法はありますか?これで、アプリケーションの起動時に開始されます。

答えて

0

あなたがそれを行うことができますいくつかの方法があります - 資源であなたのストーリーボードを定義し、ただ、コードから開始ボタンのスタイルVisualStatesこのためを使用したり、行動を使用してXAMLで全力を尽くすが拡張。後者は次のように見えます(最初は、ビヘイビアXAMLへの参照を追加してください)。

<!--add needed namespaces--> 
xmlns:interactivity="using:Microsoft.Xaml.Interactivity" 
xmlns:icore="using:Microsoft.Xaml.Interactions.Core" 
xmlns:imedia="using:Microsoft.Xaml.Interactions.Media" 

<Button x:Name="button" > 
    <Button.Projection> 
     <PlaneProjection RotationZ="50"/> 
    </Button.Projection> 
    <interactivity:Interaction.Behaviors> 
     <icore:EventTriggerBehavior EventName="Click" SourceObject="{Binding ElementName=button}"> 
      <imedia:ControlStoryboardAction> 
       <imedia:ControlStoryboardAction.Storyboard> 
        <Storyboard x:Name="Storyboard1"> 
         <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Projection).(PlaneProjection.RotationZ)" Storyboard.TargetName="button"> 
          <EasingDoubleKeyFrame KeyTime="0" Value="50"/> 
          <EasingDoubleKeyFrame KeyTime="0:0:2" Value="320"/> 
         </DoubleAnimationUsingKeyFrames> 
        </Storyboard> 
       </imedia:ControlStoryboardAction.Storyboard> 
      </imedia:ControlStoryboardAction> 
     </icore:EventTriggerBehavior> 
    </interactivity:Interaction.Behaviors> 
</Button> 
関連する問題