Gridに複数枚Canvasを配置しています。
これを1コマとみてページ1から順にアニメーション(コマ送り)をしたいと思っています。
どのような方法があるでしょうか。
アニメーションに疎いので誰か教えてください。お願いします。
気になる質問をクリップする
クリップした質問は、後からいつでもMYページで確認できます。
またクリップした質問に回答があった際、通知やメールを受け取ることができます。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
回答1件
0
ベストアンサー
WPF/UWP でのアニメーションには XAML を使って値を変更するタイプのものが一般的に用いられますが、今回の場合は C# で変更した方が簡単に実装できます。
lang
1<DockPanel> 2 <Button Click="StartAnimation" Content="スタート" DockPanel.Dock="Top" /> 3 <Grid> 4 <Grid Name="Grid1" Visibility="Visible"> 5 <Rectangle Fill="Blue" /> 6 </Grid> 7 <Grid Name="Grid2" Visibility="Collapsed"> 8 <Rectangle Fill="Red" /> 9 </Grid> 10 <Grid Name="Grid3" Visibility="Collapsed"> 11 <Rectangle Fill="Yellow" /> 12 </Grid> 13 <Grid Name="Grid4" Visibility="Collapsed"> 14 <Rectangle Fill="Green" /> 15 </Grid> 16 <Grid Name="Grid5" Visibility="Collapsed"> 17 <Rectangle Fill="Black" /> 18 </Grid> 19 </Grid> 20</DockPanel>
lang
1private void StartAnimation(object sender, RoutedEventArgs e) 2{ 3 var grids = new[] 4 { 5 this.Grid1, 6 this.Grid2, 7 this.Grid3, 8 this.Grid4, 9 this.Grid5, 10 }; 11 var timer = new DispatcherTimer(DispatcherPriority.Normal) { Interval = new TimeSpan(0, 0, 1) }; 12 timer.Tick += (_, __) => 13 { 14 var current = grids.FirstOrDefault(x => x.Visibility == Visibility.Visible); 15 foreach (var grid in grids) 16 { 17 grid.Visibility = Visibility.Collapsed; 18 } 19 var index = Array.IndexOf(grids, current); 20 var next = index == grids.Length - 1 ? grids[0] : grids[index + 1]; 21 next.Visibility = Visibility.Visible; 22 }; 23 timer.Start(); 24}
P.S. 質問の内容から WPF/UWP であると判断しましたが、次から C# の代わりに WPF/UWP をタイトルに付したほうが回答が得られやすいと思います。
投稿2016/02/19 07:24
総合スコア1610
あなたの回答
tips
太字
斜体
打ち消し線
見出し
引用テキストの挿入
コードの挿入
リンクの挿入
リストの挿入
番号リストの挿入
表の挿入
水平線の挿入
プレビュー
質問の解決につながる回答をしましょう。 サンプルコードなど、より具体的な説明があると質問者の理解の助けになります。 また、読む側のことを考えた、分かりやすい文章を心がけましょう。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/02/19 07:36