私はストーリーボードのアニメーションが初めてですが、これは簡単な方法では解決できない問題かもしれないと思います。それにもかかわらず、私はここで私の運を試みます、多分あなたの人のうちの誰かが私を助ける方法を知っています。ストーリーボードはスタイルから完了しましたか?
私のシナリオ:私のアプリケーションでは、フェードイン効果を持つポップアップを表示したいと思います。私はMVVMを介してこれをやりたいので、フェイデン効果とポップアップをラップするコントロールはコードビハインドを使用しないでください。アプリケーションは新しいメッセージを表示するためにこのコントロールのdatacontextを新しいビューモデルにリセットする必要があります。
私の問題は、スタイルにfadeinアニメーションを設定する必要があるため、アニメーションが終了したときを特定できないということです。
私のXAMLは、次のようになります。
<UserControl.Resources>
<Style x:Key="popupStyle" TargetType="{x:Type Border}" >
<Style.Triggers>
<Trigger Property="Visibility" Value="Visible">
<Trigger.EnterActions>
<BeginStoryboard>
<Storyboard x:Name="FadingStoryBoard">
<DoubleAnimation Storyboard.TargetProperty="Opacity" From="0.05" To="1" BeginTime="0:0:1" Duration="0:0:2.5" >
<DoubleAnimation.EasingFunction>
<ExponentialEase Exponent="5" EasingMode="EaseIn" />
</DoubleAnimation.EasingFunction>
</DoubleAnimation>
<DoubleAnimation Storyboard.TargetProperty="Opacity" From="1" To="0" BeginTime="0:0:6" Duration="0:0:8.5" >
<DoubleAnimation.EasingFunction>
<ExponentialEase Exponent="15" EasingMode="EaseOut" />
</DoubleAnimation.EasingFunction>
</DoubleAnimation>
</Storyboard>
</BeginStoryboard>
</Trigger.EnterActions>
</Trigger>
</Style.Triggers>
</Style>
</UserControl.Resources>
<Popup Name="Popup" IsOpen="{Binding IsVisible}" Height="{Binding PopupHeight}" Width="{Binding PopupWidth}" VerticalOffset="{Binding PopupVerticalOffset}" HorizontalOffset="{Binding PopupHorizontalOffset}" PopupAnimation="Fade" AllowsTransparency="True">
<Border Style="{StaticResource popupStyle}" Name="PopupContent" Padding="1" BorderBrush="#000000" Background="AliceBlue" CornerRadius="5" BorderThickness="3,3,3,3">
<!-- Events -->
<interact:Interaction.Triggers>
<interact:EventTrigger EventName="PreviewMouseDown">
<cmd:EventToCommand Command="{Binding Path=PopupMouseDownCommand}" PassEventArgsToCommand="True" />
</interact:EventTrigger>
</interact:Interaction.Triggers>
<DockPanel Name="ContentContainer" Background="Black" LastChildFill="True">
<Image Source="{Binding MessageIcon}" DockPanel.Dock="Left" Margin="5,0,5,0" Width="32" Height="32" />
<StackPanel Background="Transparent" DockPanel.Dock="Right" Margin="3">
<TextBlock Name="PopupHeaderTextBlock" Margin="0,3,0,5" TextWrapping="Wrap" FontSize="10" Text="{Binding PopupHeaderText}" Foreground="White" Background="Transparent" />
<TextBlock Name="PopupTextBlock" Text="{Binding PopupText}" TextWrapping="Wrap" FontSize="10" Foreground="White" Background="Transparent" />
</StackPanel>
</DockPanel>
</Border>
</Popup>
誰でもストーリーボードが終了したとき、私は私のViewModelで通知を受け取ることができますどのように任意のアイデア?
スタイル内で動作しない – KroaX
@KoraXイベントをコードの後ろに付けることができます。私は例を示すために私の答えを更新します。 – JKor
私はMVVMパターンを使用し、コードビハインドからストーリーボードにアクセスすることはできません。私はこれを回避策として使用することを考えましたが、XAMLのソリューションを好むでしょう – KroaX