回答編集履歴
1
見直しキャンペーン中
test
CHANGED
@@ -1,333 +1,168 @@
|
|
1
1
|
ちょっとやりたいことが見えないので外しているかもしれませんが、3パターンで`BeginStoryboard`しました。
|
2
|
-
|
3
2
|
肝心のアニメーションがないので、色を変えるだけのつまらないアニメーションになってしまいました^^;
|
4
3
|
|
5
|
-
|
6
|
-
|
7
4
|
* 朝 コードビハインドでキック
|
8
|
-
|
9
5
|
* 昼 `EventTrigger`でキック
|
10
|
-
|
11
6
|
* 夜 `DataTrigger`でキック
|
12
7
|
|
13
|
-
|
14
|
-
|
15
|
-
```x
|
8
|
+
```xml
|
16
|
-
|
17
9
|
<Window
|
18
|
-
|
19
10
|
x:Class="Questions298961.MainWindow"
|
20
|
-
|
21
11
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
22
|
-
|
23
12
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
24
|
-
|
25
13
|
xmlns:local="clr-namespace:Questions298961"
|
26
|
-
|
27
14
|
x:Name="window"
|
28
|
-
|
29
15
|
Title="MainWindow"
|
30
|
-
|
31
16
|
Width="450"
|
32
|
-
|
33
17
|
Height="450">
|
34
18
|
|
35
|
-
|
36
|
-
|
37
19
|
<Window.Resources>
|
38
|
-
|
39
20
|
<!-- コードビハインドでキック -->
|
40
|
-
|
41
21
|
<Storyboard x:Key="MorningAnimation">
|
42
|
-
|
43
22
|
<ColorAnimationUsingKeyFrames Storyboard.TargetName="window" Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Color)">
|
44
|
-
|
45
23
|
<EasingColorKeyFrame KeyTime="0:0:1" Value="#FFFFA400" />
|
46
|
-
|
47
24
|
</ColorAnimationUsingKeyFrames>
|
48
|
-
|
49
25
|
</Storyboard>
|
50
|
-
|
51
26
|
<!-- EventTriggerでキック -->
|
52
|
-
|
53
27
|
<Storyboard x:Key="EveningAnimation">
|
54
|
-
|
55
28
|
<ColorAnimationUsingKeyFrames Storyboard.TargetName="window" Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Color)">
|
56
|
-
|
57
29
|
<EasingColorKeyFrame KeyTime="0:0:1" Value="#FF0388FF" />
|
58
|
-
|
59
30
|
</ColorAnimationUsingKeyFrames>
|
60
|
-
|
61
31
|
</Storyboard>
|
62
|
-
|
63
32
|
<!-- DataTriggerでキック -->
|
64
|
-
|
65
33
|
<Storyboard x:Key="NightAnimation">
|
66
|
-
|
67
34
|
<ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Color)">
|
68
|
-
|
69
35
|
<EasingColorKeyFrame KeyTime="0:0:1" Value="#FF02067A" />
|
70
|
-
|
71
36
|
</ColorAnimationUsingKeyFrames>
|
72
|
-
|
73
37
|
</Storyboard>
|
74
|
-
|
75
38
|
<Style TargetType="{x:Type Button}">
|
76
|
-
|
77
39
|
<Setter Property="Width" Value="100" />
|
78
|
-
|
79
40
|
<Setter Property="Height" Value="50" />
|
80
|
-
|
81
41
|
<Setter Property="FontSize" Value="24" />
|
82
|
-
|
83
42
|
</Style>
|
84
|
-
|
85
43
|
</Window.Resources>
|
86
44
|
|
87
|
-
|
88
|
-
|
89
45
|
<Window.Style>
|
90
|
-
|
91
46
|
<Style>
|
92
|
-
|
93
47
|
<Style.Triggers>
|
94
|
-
|
95
48
|
<DataTrigger Binding="{Binding Now}" Value="{x:Static local:Period.NIGHT}">
|
96
|
-
|
97
49
|
<DataTrigger.EnterActions>
|
98
|
-
|
99
50
|
<BeginStoryboard Storyboard="{StaticResource NightAnimation}" />
|
100
|
-
|
101
51
|
</DataTrigger.EnterActions>
|
102
|
-
|
103
52
|
</DataTrigger>
|
104
|
-
|
105
53
|
</Style.Triggers>
|
106
|
-
|
107
54
|
</Style>
|
108
|
-
|
109
55
|
</Window.Style>
|
110
56
|
|
111
|
-
|
112
|
-
|
113
57
|
<Canvas>
|
114
|
-
|
115
58
|
<TextBlock
|
116
|
-
|
117
59
|
Canvas.Left="111"
|
118
|
-
|
119
60
|
Canvas.Top="98"
|
120
|
-
|
121
61
|
Width="219"
|
122
|
-
|
123
62
|
Height="100"
|
124
|
-
|
125
63
|
FontSize="36"
|
126
|
-
|
127
64
|
Text="{Binding Path=Phrase}"
|
128
|
-
|
129
65
|
TextWrapping="Wrap" />
|
130
|
-
|
131
66
|
<Button
|
132
|
-
|
133
67
|
Canvas.Left="30"
|
134
|
-
|
135
68
|
Canvas.Top="250"
|
136
|
-
|
137
69
|
Click="Click_Morning"
|
138
|
-
|
139
70
|
Content="朝" />
|
140
|
-
|
141
71
|
<Button
|
142
|
-
|
143
72
|
Canvas.Left="170"
|
144
|
-
|
145
73
|
Canvas.Top="250"
|
146
|
-
|
147
74
|
Click="Click_Evening"
|
148
|
-
|
149
75
|
Content="昼">
|
150
|
-
|
151
76
|
<Button.Triggers>
|
152
|
-
|
153
77
|
<EventTrigger RoutedEvent="Button.Click">
|
154
|
-
|
155
78
|
<BeginStoryboard Storyboard="{StaticResource EveningAnimation}" />
|
156
|
-
|
157
79
|
</EventTrigger>
|
158
|
-
|
159
80
|
</Button.Triggers>
|
160
|
-
|
161
81
|
</Button>
|
162
|
-
|
163
82
|
<Button
|
164
|
-
|
165
83
|
Canvas.Left="310"
|
166
|
-
|
167
84
|
Canvas.Top="250"
|
168
|
-
|
169
85
|
Click="Click_Night"
|
170
|
-
|
171
86
|
Content="夜" />
|
172
|
-
|
173
87
|
<Button
|
174
|
-
|
175
88
|
Canvas.Left="170"
|
176
|
-
|
177
89
|
Canvas.Top="325"
|
178
|
-
|
179
90
|
Click="Click_Greeting"
|
180
|
-
|
181
91
|
Content="あいさつ" />
|
182
|
-
|
183
92
|
</Canvas>
|
184
|
-
|
185
93
|
</Window>
|
186
|
-
|
187
94
|
```
|
188
95
|
|
189
|
-
|
190
|
-
|
191
|
-
```
|
96
|
+
```cs
|
192
|
-
|
193
97
|
using System.ComponentModel;
|
194
|
-
|
195
98
|
using System.Windows;
|
196
|
-
|
197
99
|
using System.Windows.Media.Animation;
|
198
100
|
|
199
|
-
|
200
|
-
|
201
101
|
namespace Questions298961
|
202
|
-
|
203
102
|
{
|
204
|
-
|
205
103
|
public enum Period { MORNING, EVENING, NIGHT };
|
206
104
|
|
207
|
-
|
208
|
-
|
209
105
|
public partial class MainWindow : Window
|
210
|
-
|
211
106
|
{
|
212
|
-
|
213
107
|
private readonly GreetingPhrase ph = new GreetingPhrase();
|
214
108
|
|
215
|
-
|
216
|
-
|
217
109
|
public MainWindow()
|
218
|
-
|
219
110
|
{
|
220
|
-
|
221
111
|
InitializeComponent();
|
222
|
-
|
223
112
|
DataContext = ph;
|
224
|
-
|
225
113
|
}
|
226
114
|
|
227
|
-
|
228
|
-
|
229
115
|
private void Click_Morning(object sender, RoutedEventArgs e)
|
230
|
-
|
231
116
|
{
|
232
|
-
|
233
117
|
ph.Now = Period.MORNING;
|
234
|
-
|
235
118
|
var sb = FindResource("MorningAnimation") as Storyboard;
|
236
|
-
|
237
119
|
BeginStoryboard(sb);
|
238
|
-
|
239
120
|
}
|
240
|
-
|
241
|
-
|
242
121
|
|
243
122
|
private void Click_Evening(object sender, RoutedEventArgs e) => ph.Now = Period.EVENING;
|
244
123
|
|
245
|
-
|
246
|
-
|
247
124
|
private void Click_Night(object sender, RoutedEventArgs e) => ph.Now = Period.NIGHT;
|
248
125
|
|
249
|
-
|
250
|
-
|
251
126
|
private void Click_Greeting(object sender, RoutedEventArgs e) => ph.ChangePhrase();
|
252
|
-
|
253
127
|
}
|
254
128
|
|
255
|
-
|
256
|
-
|
257
129
|
public class GreetingPhrase : INotifyPropertyChanged
|
258
|
-
|
259
130
|
{
|
260
|
-
|
261
131
|
public string Phrase { get; set; }
|
262
132
|
|
263
|
-
|
264
|
-
|
265
133
|
private Period _Now;
|
266
|
-
|
267
134
|
public Period Now
|
268
|
-
|
269
135
|
{
|
270
|
-
|
271
136
|
get => _Now;
|
272
|
-
|
273
137
|
set
|
274
|
-
|
275
138
|
{
|
276
|
-
|
277
139
|
_Now = value;
|
278
|
-
|
279
140
|
RaiseProeprtyChanged(nameof(Now));
|
280
|
-
|
281
141
|
}
|
282
|
-
|
283
142
|
}
|
284
143
|
|
285
|
-
|
286
|
-
|
287
144
|
public void ChangePhrase()
|
288
|
-
|
289
145
|
{
|
290
|
-
|
291
146
|
switch(Now)
|
292
|
-
|
293
147
|
{
|
294
|
-
|
295
148
|
case Period.MORNING:
|
296
|
-
|
297
149
|
Phrase = "おはよう!";
|
298
|
-
|
299
150
|
break;
|
300
|
-
|
301
151
|
case Period.EVENING:
|
302
|
-
|
303
152
|
Phrase = "こんにちは!";
|
304
|
-
|
305
153
|
break;
|
306
|
-
|
307
154
|
case Period.NIGHT:
|
308
|
-
|
309
155
|
Phrase = "こんばんは!";
|
310
|
-
|
311
156
|
break;
|
312
|
-
|
313
157
|
}
|
314
|
-
|
315
158
|
RaiseProeprtyChanged(nameof(Phrase));
|
316
|
-
|
317
159
|
}
|
318
160
|
|
319
|
-
|
320
|
-
|
321
161
|
#region INotifyPropertyChanged の実装
|
322
|
-
|
323
162
|
public event PropertyChangedEventHandler PropertyChanged;
|
324
|
-
|
325
163
|
private void RaiseProeprtyChanged(string propertyName) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
326
|
-
|
327
164
|
#endregion
|
328
|
-
|
329
165
|
}
|
330
|
-
|
331
166
|
}
|
332
|
-
|
333
167
|
```
|
168
|
+
![アプリ動画](https://ddjkaamml8q8x.cloudfront.net/questions/2023-07-23/1bbd3d3b-e9b5-4a2e-8a15-e76c2f750019.gif)
|