ストーリーボードは、Visual Studioの素晴らしい体験ではなく、手動で書き込むことがベストセラーではないかもしれません。
Visual Studioのインストールに含まれるBlendでプロジェクトを開くことをお勧めします。これは、アプリケーションを設計するための優れたツールです。特に、ストーリーボードを非常に簡単に追加できます。また、ストーリーボードXAMLが自動的に生成され、デザイナーの変更が表示されます。
あなたのアニメーションのシナリオでは、ページ内でXAMLテンプレートを使って遊んだことがあり、折りたたみと拡大のように見えるものが出てきましたが、Visibilityプロパティを次のように操作することなく行います:
<VisualStateGroup x:Name="State">
<VisualState x:Name="Visible">
<Storyboard>
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="Grid">
<EasingDoubleKeyFrame KeyTime="0" Value="0"/>
<EasingDoubleKeyFrame KeyTime="0:0:0.2" Value="0"/>
<EasingDoubleKeyFrame KeyTime="0:0:0.3" Value="1"/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.ScaleY)" Storyboard.TargetName="Grid">
<EasingDoubleKeyFrame KeyTime="0" Value="0"/>
<EasingDoubleKeyFrame KeyTime="0:0:0.3" Value="1"/>
</DoubleAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="Grid">
<DiscreteObjectKeyFrame KeyTime="0">
<DiscreteObjectKeyFrame.Value>
<Visibility>Collapsed</Visibility>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
<DiscreteObjectKeyFrame KeyTime="0:0:0.1">
<DiscreteObjectKeyFrame.Value>
<Visibility>Visible</Visibility>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
<VisualState x:Name="Collapsed">
<Storyboard>
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="Grid">
<EasingDoubleKeyFrame KeyTime="0" Value="1"/>
<EasingDoubleKeyFrame KeyTime="0:0:0.1" Value="0"/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.ScaleY)" Storyboard.TargetName="Grid">
<EasingDoubleKeyFrame KeyTime="0" Value="1"/>
<EasingDoubleKeyFrame KeyTime="0:0:0.3" Value="0"/>
</DoubleAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="Grid">
<DiscreteObjectKeyFrame KeyTime="0">
<DiscreteObjectKeyFrame.Value>
<Visibility>Visible</Visibility>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
<DiscreteObjectKeyFrame KeyTime="0:0:0.2">
<DiscreteObjectKeyFrame.Value>
<Visibility>Collapsed</Visibility>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
</VisualStateGroup>
ます。また、このように見えるように、あなたのコンテンツグリッドを変更したいと思う:
<Grid x:Name="Grid" Grid.Row="1" RenderTransformOrigin="0.5,0">
<Grid.RenderTransform>
<CompositeTransform/>
</Grid.RenderTransform>
<ContentPresenter x:Name="ContentPresenter" Content="{TemplateBinding Content}" />
</Grid>
あなたがグリッドに変更を加える必要がありますし、ストーリーボードは、次の何をすべきか、なぜ私が説明します。
あなたが探しているものと似たようなものを実現するために、グリッドの不透明度とYスケールをアニメーション化することを選択しました。
コントロールのYスケールを操作するので、GridにRenderTransformを追加しました。 CompositeTransformを使用する理由は、最も一般的な変換(スケール、回転、変換など)を操作できるようにするためです。
状態では、キーフレームを使用して時間の経過とともに値を操作します。これはストーリーボードでアニメーションを達成する方法です。時間が0のKeyFrameを1つだけ設定すると、プロパティを変更するVisualState.Settersメカニズムを使用するのと同じような即時の変更として表示されます。
Collapsed状態では、グリッドの不透明度とYスケーリングを1から0に変更しています。これにより、コンテンツがヘッダーに折り畳まれていることを示すアニメーションが表示されます。キーフレームからわかるように、私たちは2つのプロパティのアニメーションをずらしているので、スケールを終了する前にコンテンツがフェードアウトします。
Visible状態では、不透明度とYスケーリングを同じ時間に0から1に変更することによって、Collapsed状態を本質的に逆転しています。
これらをコントロールに読み込んで、Blendで再生してみてください。私がこれを非常に素早く一緒に投げたので、それは素晴らしい出発点です。
あなたはここにブレンドを使用してストーリーボードにいくつかのより多くの情報を見つけることができます:https://blogs.msdn.microsoft.com/avtarsohi/2016/02/16/understand-storyboard-concept-in-xaml-using-blend-2015/
これはまだVisibilityプロパティの変更を使用して動作しますか? – JCrook1121
@ JCrook1121あなたがそれを使用できなかった理由はありません。私は自分の答えを更新して、どのように使用できるかを示します。 –
ありがとう!私が尋ねた唯一の理由は、ページの上部にいくつかのコンテンツのコントロールを使用し、コントロールの下にいくつかのコンテンツがあると、あなたの例がうまく動作しないためです。あなたが崩壊すると、倒れたように見えるようにアニメートされますが、その下のコンテンツは盛り上がっていません。 – JCrook1121