當前位置: 首頁>>代碼示例>>C#>>正文


C# Storyboard.Resume方法代碼示例

本文整理匯總了C#中Windows.UI.Xaml.Media.Animation.Storyboard.Resume方法的典型用法代碼示例。如果您正苦於以下問題:C# Storyboard.Resume方法的具體用法?C# Storyboard.Resume怎麽用?C# Storyboard.Resume使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Windows.UI.Xaml.Media.Animation.Storyboard的用法示例。


在下文中一共展示了Storyboard.Resume方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: AddGunDanmu


//.........這裏部分代碼省略.........
                grid.Margin = new Thickness(0, 0, 20, 0);
                grid.VerticalAlignment = VerticalAlignment.Center;
                grid.HorizontalAlignment = HorizontalAlignment.Left;
                if (fontFamily != "默認")
                {
                    tx.FontFamily = new FontFamily(fontFamily);
                    tx2.FontFamily = new FontFamily(fontFamily);
                }
                tx2.Text = model.DanText;
                tx.Text = model.DanText;
                tx2.Foreground = new SolidColorBrush(Color.FromArgb(255, 0, 0, 0));
                tx.Foreground = model.DanColor;
                //彈幕大小
                double size = double.Parse(model.DanSize);
                if (size == 25)
                {
                    tx2.FontSize = fontSize;
                    tx.FontSize = fontSize;
                }
                else
                {
                    tx2.FontSize = fontSize - 2;
                    tx.FontSize = fontSize - 2;
                }

                //grid包含彈幕文本信息
                grid.Children.Add(tx2);
                grid.Children.Add(tx);
                grid.VerticalAlignment = VerticalAlignment.Top;
                grid.HorizontalAlignment = HorizontalAlignment.Left;

                TranslateTransform moveTransform = new TranslateTransform();
                moveTransform.X = grid_Danmu.ActualWidth;
                grid.RenderTransform = moveTransform;
                //將彈幕加載入控件中,並且設置位置
                grid_Danmu.Children.Add(grid);
                Grid.SetRow(grid, row);
                row++;
                if (row == maxRow)
                {
                    row = 0;
                }
                tx2.Margin = new Thickness(1);
                if (Myself)
                {
                    grid.BorderThickness = new Thickness(2);
                    grid.BorderBrush = new SolidColorBrush(Colors.Gray);
                }
                grid.Opacity = Tran;
                grid.DataContext = model;
                //更新彈幕UI,不更新無法獲得彈幕的ActualWidth
                grid.UpdateLayout();
                //創建動畫
                Duration duration = new Duration(TimeSpan.FromSeconds(Speed));
                DoubleAnimation myDoubleAnimationX = new DoubleAnimation();
                myDoubleAnimationX.Duration = duration;
                //創建故事版
                Storyboard justintimeStoryboard = new Storyboard();
                justintimeStoryboard.Duration = duration;
                myDoubleAnimationX.To = -(grid.ActualWidth);//到達
                justintimeStoryboard.Children.Add(myDoubleAnimationX);
                Storyboard.SetTarget(myDoubleAnimationX, moveTransform);
                //故事版加入動畫
                Storyboard.SetTargetProperty(myDoubleAnimationX, "X");
                grid_Danmu.Resources.Remove("justintimeStoryboard");
                grid_Danmu.Resources.Add("justintimeStoryboard", justintimeStoryboard);
                justintimeStoryboard.Begin();
                //等待,暫停則暫停
                await Task.Run(async () =>
                {
                    int i = 0;
                    while (true)
                    {
                        if (!IsPlaying)
                        {
                            await this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => {
                                justintimeStoryboard.Pause();
                            });
                            //break;
                        }
                        else
                        {
                            if (i == Speed*2)
                            {
                                break;
                            }
                            i++;
                            await this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => {
                                justintimeStoryboard.Resume();
                            });
                        }
                        await Task.Delay(500);
                    }
                });
                grid_Danmu.Children.Remove(grid);
            }
            catch (Exception)
            {
            }
        }
開發者ID:GeminiLab,項目名稱:BiliBili-UWP,代碼行數:101,代碼來源:MyDanmaku.xaml.cs


注:本文中的Windows.UI.Xaml.Media.Animation.Storyboard.Resume方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。