質問編集履歴
7
MainWindow.xamlに MediaElementの記述漏れがあったため、修正しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -62,6 +62,7 @@
|
|
62
62
|
</Window.Resources>
|
63
63
|
|
64
64
|
<Canvas>
|
65
|
+
<MediaElement x:Name = "media"/>
|
65
66
|
<Canvas x:Name="ObjectLayer">
|
66
67
|
<Image x:Name="Object"
|
67
68
|
Source="object.png"
|
6
ソースコードを修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -15,15 +15,20 @@
|
|
15
15
|
public MainWindow()
|
16
16
|
{
|
17
17
|
InitializeComponent();
|
18
|
-
var sb = FindResource("SampleStoryboard") as Storyboard;
|
19
|
-
sb.Completed += SampleSb_Completed;
|
20
|
-
sb.Begin();
|
21
18
|
}
|
22
19
|
|
23
|
-
private void
|
20
|
+
private void Page_Loaded(object sender, RoutedEventArgs e)
|
24
21
|
{
|
22
|
+
var sb = FindResource("SampleStoryboard") as Storyboard;
|
25
|
-
|
23
|
+
sb.Completed += Sb_Completed;
|
24
|
+
BeginStoryboard(sb);
|
26
25
|
}
|
26
|
+
|
27
|
+
private void Sb_Completed(object sender, EventArgs e)
|
28
|
+
{
|
29
|
+
Debug.WriteLine("イベント発生");
|
30
|
+
}
|
31
|
+
|
27
32
|
}
|
28
33
|
}
|
29
34
|
```
|
@@ -48,29 +53,41 @@
|
|
48
53
|
</ResourceDictionary.MergedDictionaries>
|
49
54
|
</ResourceDictionary>
|
50
55
|
</Window.Resources>
|
51
|
-
<
|
56
|
+
<Window.Resources>
|
57
|
+
<ResourceDictionary>
|
58
|
+
<ResourceDictionary.MergedDictionaries>
|
59
|
+
<ResourceDictionary Source="SampleDictionary.xaml"/>
|
60
|
+
</ResourceDictionary.MergedDictionaries>
|
61
|
+
</ResourceDictionary>
|
62
|
+
</Window.Resources>
|
63
|
+
|
52
|
-
|
64
|
+
<Canvas>
|
53
|
-
<Canvas x:Name="ObjectLayer"
|
65
|
+
<Canvas x:Name="ObjectLayer">
|
54
|
-
d:Visibility="Visible"
|
55
|
-
Height="768" Width="1024"
|
56
|
-
Background="Transparent">
|
57
|
-
<Image x:Name="Object"
|
66
|
+
<Image x:Name="Object"
|
67
|
+
Source="object.png"
|
58
|
-
|
68
|
+
Height="349" Width="301"
|
69
|
+
Canvas.Left="374" Canvas.Top="284"
|
70
|
+
RenderTransformOrigin="0.5,0.5">
|
71
|
+
<Image.RenderTransform>
|
72
|
+
<TransformGroup>
|
73
|
+
<ScaleTransform/>
|
74
|
+
</TransformGroup>
|
75
|
+
</Image.RenderTransform>
|
76
|
+
</Image>
|
59
77
|
</Canvas>
|
78
|
+
|
60
79
|
<Canvas x:Name="CharaLayer"
|
61
80
|
d:Visibility="Visible"
|
62
81
|
Height="768" Width="1024"
|
63
82
|
Background="Transparent">
|
83
|
+
<Image x:Name="Char1"
|
84
|
+
Source="char1.png"
|
85
|
+
Height="350" Canvas.Left="9" Canvas.Top="414" HorizontalAlignment="Center" VerticalAlignment="Top"/>
|
64
86
|
<Image x:Name="Char2"
|
65
|
-
Source="char.png"
|
87
|
+
Source="char2.png"
|
66
|
-
Height="350" Canvas.Left="9" Canvas.Top="414" HorizontalAlignment="Center" VerticalAlignment="Top"/>
|
67
|
-
<Image x:Name="Char1"
|
68
|
-
Source="char.png"
|
69
88
|
Height="350" Canvas.Left="767" Canvas.Top="414" HorizontalAlignment="Left" VerticalAlignment="Center"/>
|
70
89
|
</Canvas>
|
71
|
-
|
72
|
-
|
90
|
+
</Canvas>
|
73
|
-
</Viewbox>
|
74
91
|
</Window>
|
75
92
|
|
76
93
|
```
|
5
誤字を修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -61,7 +61,7 @@
|
|
61
61
|
d:Visibility="Visible"
|
62
62
|
Height="768" Width="1024"
|
63
63
|
Background="Transparent">
|
64
|
-
<Image x:Name="Char
|
64
|
+
<Image x:Name="Char2"
|
65
65
|
Source="char.png"
|
66
66
|
Height="350" Canvas.Left="9" Canvas.Top="414" HorizontalAlignment="Center" VerticalAlignment="Top"/>
|
67
67
|
<Image x:Name="Char1"
|
4
MainWindow.xamlの詳細なソースコードを追記しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -57,6 +57,18 @@
|
|
57
57
|
<Image x:Name="Object"
|
58
58
|
Source="<!-- Path -->" />
|
59
59
|
</Canvas>
|
60
|
+
<Canvas x:Name="CharaLayer"
|
61
|
+
d:Visibility="Visible"
|
62
|
+
Height="768" Width="1024"
|
63
|
+
Background="Transparent">
|
64
|
+
<Image x:Name="Char1"
|
65
|
+
Source="char.png"
|
66
|
+
Height="350" Canvas.Left="9" Canvas.Top="414" HorizontalAlignment="Center" VerticalAlignment="Top"/>
|
67
|
+
<Image x:Name="Char1"
|
68
|
+
Source="char.png"
|
69
|
+
Height="350" Canvas.Left="767" Canvas.Top="414" HorizontalAlignment="Left" VerticalAlignment="Center"/>
|
70
|
+
</Canvas>
|
71
|
+
|
60
72
|
</Canvas>
|
61
73
|
</Viewbox>
|
62
74
|
</Window>
|
@@ -71,7 +83,7 @@
|
|
71
83
|
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="Object" Storyboard.TargetProperty="Source">
|
72
84
|
<DiscreteObjectKeyFrame KeyTime="0">
|
73
85
|
<DiscreteObjectKeyFrame.Value>
|
74
|
-
<BitmapImage UriSource="
|
86
|
+
<BitmapImage UriSource="image.png"/>
|
75
87
|
</DiscreteObjectKeyFrame.Value>
|
76
88
|
</DiscreteObjectKeyFrame>
|
77
89
|
</ObjectAnimationUsingKeyFrames>
|
@@ -113,7 +125,7 @@
|
|
113
125
|
</EasingDoubleKeyFrame>
|
114
126
|
</DoubleAnimationUsingKeyFrames>
|
115
127
|
<!-- 効果音・会話 -->
|
116
|
-
<MediaTimeline Source="
|
128
|
+
<MediaTimeline Source="se.mp3" Storyboard.TargetName="media" BeginTime="00:00:02"/>
|
117
129
|
</Storyboard>
|
118
130
|
|
119
131
|
</ResourceDictionary>
|
3
Storyboardの詳細なコードを追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -65,9 +65,57 @@
|
|
65
65
|
```ResourceDictionary.xaml
|
66
66
|
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
67
67
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
|
68
|
+
|
68
69
|
<Storyboard x:Key="SampleStoryboard">
|
69
|
-
<!--
|
70
|
+
<!-- Objectに画像をセット -->
|
71
|
+
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="Object" Storyboard.TargetProperty="Source">
|
72
|
+
<DiscreteObjectKeyFrame KeyTime="0">
|
73
|
+
<DiscreteObjectKeyFrame.Value>
|
74
|
+
<BitmapImage UriSource="resources\image\element\image.png"/>
|
75
|
+
</DiscreteObjectKeyFrame.Value>
|
76
|
+
</DiscreteObjectKeyFrame>
|
77
|
+
</ObjectAnimationUsingKeyFrames>
|
78
|
+
|
79
|
+
<!-- キャラクターフェードイン -->
|
80
|
+
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="CharaLayer" Storyboard.TargetProperty="Visibility">
|
81
|
+
<DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Visible}"/>
|
82
|
+
</ObjectAnimationUsingKeyFrames>
|
83
|
+
<DoubleAnimationUsingKeyFrames Storyboard.TargetName="CharaLayer"
|
84
|
+
Storyboard.TargetProperty="(UIElement.Opacity)">
|
85
|
+
<EasingDoubleKeyFrame KeyTime="00:00:00" Value="0"/>
|
86
|
+
<EasingDoubleKeyFrame KeyTime="00:00:01" Value="1">
|
87
|
+
<EasingDoubleKeyFrame.EasingFunction>
|
88
|
+
<QuarticEase EasingMode="EaseIn"/>
|
89
|
+
</EasingDoubleKeyFrame.EasingFunction>
|
90
|
+
</EasingDoubleKeyFrame>
|
91
|
+
</DoubleAnimationUsingKeyFrames>
|
92
|
+
|
93
|
+
<!-- Objectのアピールイン -->
|
94
|
+
<DoubleAnimationUsingKeyFrames Storyboard.TargetName="Object" Storyboard.TargetProperty="(UIElement.Opacity)">
|
95
|
+
<EasingDoubleKeyFrame KeyTime="00:00:00" Value="0"/>
|
96
|
+
<EasingDoubleKeyFrame KeyTime="00:00:02" Value="0"/>
|
97
|
+
<EasingDoubleKeyFrame KeyTime="00:00:02.5" Value="1"/>
|
98
|
+
</DoubleAnimationUsingKeyFrames>
|
99
|
+
<DoubleAnimationUsingKeyFrames Storyboard.TargetName="Object" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)">
|
100
|
+
<EasingDoubleKeyFrame KeyTime="00:00:02" Value="1.5"/>
|
101
|
+
<EasingDoubleKeyFrame KeyTime="00:00:02.5" Value="1">
|
102
|
+
<EasingDoubleKeyFrame.EasingFunction>
|
103
|
+
<BackEase EasingMode="EaseIn"/>
|
104
|
+
</EasingDoubleKeyFrame.EasingFunction>
|
105
|
+
</EasingDoubleKeyFrame>
|
106
|
+
</DoubleAnimationUsingKeyFrames>
|
107
|
+
<DoubleAnimationUsingKeyFrames Storyboard.TargetName="Object" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)">
|
108
|
+
<EasingDoubleKeyFrame KeyTime="00:00:02" Value="1.5"/>
|
109
|
+
<EasingDoubleKeyFrame KeyTime="00:00:02.5" Value="1">
|
110
|
+
<EasingDoubleKeyFrame.EasingFunction>
|
111
|
+
<BackEase EasingMode="EaseIn"/>
|
112
|
+
</EasingDoubleKeyFrame.EasingFunction>
|
113
|
+
</EasingDoubleKeyFrame>
|
114
|
+
</DoubleAnimationUsingKeyFrames>
|
115
|
+
<!-- 効果音・会話 -->
|
116
|
+
<MediaTimeline Source="resources\sound\se\se1.mp3" Storyboard.TargetName="media" BeginTime="00:00:02"/>
|
70
117
|
</Storyboard>
|
118
|
+
|
71
119
|
</ResourceDictionary>
|
72
120
|
```
|
73
121
|
|
2
コメントの方法を試した結果を追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -76,3 +76,38 @@
|
|
76
76
|
C#10.0
|
77
77
|
WPF
|
78
78
|
|
79
|
+
###追記
|
80
|
+
コメントで教えていただいた、クローンを使う方法を試しました。
|
81
|
+
結果、以下の例外が発生しました。
|
82
|
+
|
83
|
+
System.InvalidOperationException:
|
84
|
+
'名前 'Object' を解決するために適用できる名前スコープがありません。'
|
85
|
+
|
86
|
+
Storyboard中で、Imageコントロール"Object"を操作しており、Cloneしたインスタンスからコントロールのプロパティを変更しようとするのがまずいのかと考えておりますが、はっきりとはしておらず調査中です。
|
87
|
+
|
88
|
+
```MainWindow.xaml.cs
|
89
|
+
namespace Sample
|
90
|
+
{
|
91
|
+
/// <summary>
|
92
|
+
/// Interaction logic for MainWindow.xaml
|
93
|
+
/// </summary>
|
94
|
+
public partial class MainWindow : Window
|
95
|
+
{
|
96
|
+
public MainWindow()
|
97
|
+
{
|
98
|
+
InitializeComponent();
|
99
|
+
<!-- 変更箇所 -->
|
100
|
+
var sb = (FindResource("SampleStoryboard") as Storyboard).Clone();
|
101
|
+
<!-- 変更ここまで -->
|
102
|
+
sb.Completed += SampleSb_Completed;
|
103
|
+
sb.Begin();
|
104
|
+
}
|
105
|
+
|
106
|
+
private void SampleSb_Completed(object? sender, EventArgs e)
|
107
|
+
{
|
108
|
+
<!-- イベント発生時の処理 -->
|
109
|
+
}
|
110
|
+
}
|
111
|
+
}
|
112
|
+
```
|
113
|
+
|
1
xamlのコードを追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -27,6 +27,41 @@
|
|
27
27
|
}
|
28
28
|
}
|
29
29
|
```
|
30
|
+
```MainWindow.xaml
|
31
|
+
<Window x:Class="Sample.MainWindow"
|
32
|
+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
33
|
+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
34
|
+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
35
|
+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
36
|
+
xmlns:gif="http://wpfanimatedgif.codeplex.com"
|
37
|
+
xmlns:local="clr-namespace:Sample"
|
38
|
+
mc:Ignorable="d"
|
39
|
+
Title="MainWindow" Height="768" Width="1024">
|
40
|
+
|
41
|
+
<Window.Background>
|
42
|
+
<ImageBrush ImageSource="/resources/bgimage/bgImage1.jpg" />
|
43
|
+
</Window.Background>
|
44
|
+
<Window.Resources>
|
45
|
+
<ResourceDictionary>
|
46
|
+
<ResourceDictionary.MergedDictionaries>
|
47
|
+
<ResourceDictionary Source="AnimationDictionary.xaml"/>
|
48
|
+
</ResourceDictionary.MergedDictionaries>
|
49
|
+
</ResourceDictionary>
|
50
|
+
</Window.Resources>
|
51
|
+
<Viewbox>
|
52
|
+
<Canvas>
|
53
|
+
<Canvas x:Name="ObjectLayer"
|
54
|
+
d:Visibility="Visible"
|
55
|
+
Height="768" Width="1024"
|
56
|
+
Background="Transparent">
|
57
|
+
<Image x:Name="Object"
|
58
|
+
Source="<!-- Path -->" />
|
59
|
+
</Canvas>
|
60
|
+
</Canvas>
|
61
|
+
</Viewbox>
|
62
|
+
</Window>
|
63
|
+
|
64
|
+
```
|
30
65
|
```ResourceDictionary.xaml
|
31
66
|
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
32
67
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
|