トップ回答者
Storyboardが最後まで再生したか?

質問
回答
-
あまり良い例ではありませんが、こんな感じでご希望のことはできるのではないでしょうか。
> 3Dゲームを作ろうと思っていて
是非頑張って下さい。
[Window1.xaml.cs]
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Windows.Media.Animation;namespace test
{
/// <summary>
/// Interaction logic for Window1.xaml
/// </summary>public partial class Window1 : System.Windows.Window
{
bool IsAnimation = false;public Window1()
{
InitializeComponent();
}void StartButton_Click(Object sender, RoutedEventArgs e)
{
if (!IsAnimation)
{
Storyboard FadeinStory = new Storyboard();
FadeinStory = (Storyboard)this.FindResource("FadeinAnimation");
FadeinStory.Completed += new EventHandler(FadeinStory_Completed);
this.BeginStoryboard(FadeinStory);
}
IsAnimation = true;
}void FadeinStory_Completed(Object sender, EventArgs e)
{
MessageBox.Show("Animation Completed !");
IsAnimation = false;
}}
}[Window1.xaml]
<Window x:Class="test.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="test" Height="300" Width="300"
>
<Window.Resources>
<Storyboard x:Key="FadeinAnimation">
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="TargetText" Storyboard.TargetProperty="(UIElement.Opacity)">
<SplineDoubleKeyFrame KeyTime="00:00:00" Value="0"/>
<SplineDoubleKeyFrame KeyTime="00:00:05" Value="1"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</Window.Resources>
<Canvas x:Name="MainCanvas">
<TextBlock x:Name="TargetText" Text="Animation Completed !" Height="30" Width="217" Canvas.Left="38" Canvas.Top="112" Opacity="0.0" FontSize="18" FontWeight="Bold"/>
<Button x:Name="StartButton" Width="74.127" Content="Start" Canvas.Left="111" Canvas.Top="190" Click="StartButton_Click"/>
</Canvas>
</Window>
すべての返信
-
Visterさん、ありがとうございます。
myStoryboard.Completed += new EventHandler(myStoryboard_Completed);
void myStoryboard_Completed(object sender, EventArgs e)
{
MessageBox.Show("myStoryboard_Completed");
}
ではアニメーションが終了しても何も起きません。これでは間違っているでしょうか?
やりたいことは具体的に言うと、3Dゲームを作ろうと思っていて、剣を振っている間にまた攻撃ボタンが押されてもアニメーションの再生を初めからせず、アニメーションを続けるようにしたいです。
-
あまり良い例ではありませんが、こんな感じでご希望のことはできるのではないでしょうか。
> 3Dゲームを作ろうと思っていて
是非頑張って下さい。
[Window1.xaml.cs]
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Windows.Media.Animation;namespace test
{
/// <summary>
/// Interaction logic for Window1.xaml
/// </summary>public partial class Window1 : System.Windows.Window
{
bool IsAnimation = false;public Window1()
{
InitializeComponent();
}void StartButton_Click(Object sender, RoutedEventArgs e)
{
if (!IsAnimation)
{
Storyboard FadeinStory = new Storyboard();
FadeinStory = (Storyboard)this.FindResource("FadeinAnimation");
FadeinStory.Completed += new EventHandler(FadeinStory_Completed);
this.BeginStoryboard(FadeinStory);
}
IsAnimation = true;
}void FadeinStory_Completed(Object sender, EventArgs e)
{
MessageBox.Show("Animation Completed !");
IsAnimation = false;
}}
}[Window1.xaml]
<Window x:Class="test.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="test" Height="300" Width="300"
>
<Window.Resources>
<Storyboard x:Key="FadeinAnimation">
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="TargetText" Storyboard.TargetProperty="(UIElement.Opacity)">
<SplineDoubleKeyFrame KeyTime="00:00:00" Value="0"/>
<SplineDoubleKeyFrame KeyTime="00:00:05" Value="1"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</Window.Resources>
<Canvas x:Name="MainCanvas">
<TextBlock x:Name="TargetText" Text="Animation Completed !" Height="30" Width="217" Canvas.Left="38" Canvas.Top="112" Opacity="0.0" FontSize="18" FontWeight="Bold"/>
<Button x:Name="StartButton" Width="74.127" Content="Start" Canvas.Left="111" Canvas.Top="190" Click="StartButton_Click"/>
</Canvas>
</Window>