/// <summary> /// 添加顶部弹幕 /// </summary> /// <param name="m">参数</param> /// <param name="own">是否自己发送的</param> public async void AddTopDanmu(DanmakuModel m, bool own) { Grid grid = null; switch (borderStyle) { case DanmakuBorderStyle.Default: grid = DanmakuItemControl.CreateControlOverlap((float)sizeZoom, bold, font, m); break; case DanmakuBorderStyle.NoBorder: grid = DanmakuItemControl.CreateControlNoBorder((float)sizeZoom, bold, font, m); break; case DanmakuBorderStyle.Shadow: grid = DanmakuItemControl.CreateControlShadow((float)sizeZoom, bold, font, m); break; case DanmakuBorderStyle.BorderV2: grid = await DanmakuItemControl.CreateControlBorder((float)sizeZoom, bold, font, m); break; default: break; } if (own) { grid.BorderBrush = new SolidColorBrush(m.color); grid.BorderThickness = new Thickness(1); } var r = ComputeTopRow(); if (r == -1) { return; } grid.HorizontalAlignment = HorizontalAlignment.Center; grid.VerticalAlignment = VerticalAlignment.Top; Grid.SetRow(grid, r); grid_Top.Children.Add(grid); //创建空转换动画 TranslateTransform moveTransform = new TranslateTransform(); //创建动画 Duration duration = new Duration(TimeSpan.FromSeconds(5)); DoubleAnimation myDoubleAnimationX = new DoubleAnimation(); myDoubleAnimationX.Duration = duration; //创建故事版 Storyboard moveStoryboard = new Storyboard(); moveStoryboard.Duration = duration; moveStoryboard.Children.Add(myDoubleAnimationX); Storyboard.SetTarget(myDoubleAnimationX, moveTransform); //故事版加入动画 Storyboard.SetTargetProperty(myDoubleAnimationX, "X"); topBottomStoryList.Add(moveStoryboard); moveStoryboard.Completed += new EventHandler <object>((senders, obj) => { grid_Top.Children.Remove(grid); grid.Children.Clear(); grid = null; topBottomStoryList.Remove(moveStoryboard); moveStoryboard.Stop(); moveStoryboard = null; }); moveStoryboard.Begin(); }
/// <summary> /// 添加直播滚动弹幕 /// </summary> /// <param name="text">参数</param> /// <param name="own">是否自己发送的</param> /// <param name="color">颜色</param> public async void AddLiveDanmu(string text, bool own, Color?color) { if (color == null) { color = Colors.White; } var m = new DanmakuModel() { text = text, color = color.Value, location = DanmakuLocation.Roll, size = 25 }; Grid grid = null; switch (borderStyle) { case DanmakuBorderStyle.Default: grid = DanmakuItemControl.CreateControlOverlap((float)sizeZoom, bold, font, m); break; case DanmakuBorderStyle.NoBorder: grid = DanmakuItemControl.CreateControlNoBorder((float)sizeZoom, bold, font, m); break; case DanmakuBorderStyle.Shadow: grid = DanmakuItemControl.CreateControlShadow((float)sizeZoom, bold, font, m); break; case DanmakuBorderStyle.BorderV2: grid = await DanmakuItemControl.CreateControlBorder((float)sizeZoom, bold, font, m); break; default: break; } if (own) { grid.BorderBrush = new SolidColorBrush(color.Value); grid.BorderThickness = new Thickness(1); } var r = ComputeRollRow(grid); if (r == -1) { return; } Grid.SetRow(grid, r); grid.HorizontalAlignment = HorizontalAlignment.Left; grid.VerticalAlignment = VerticalAlignment.Center; grid_Roll.Children.Add(grid); grid_Roll.UpdateLayout(); TranslateTransform moveTransform = new TranslateTransform(); moveTransform.X = gv.ActualWidth; grid.RenderTransform = moveTransform; //创建动画 Duration duration = new Duration(TimeSpan.FromSeconds(speed)); DoubleAnimation myDoubleAnimationX = new DoubleAnimation(); myDoubleAnimationX.Duration = duration; //创建故事版 Storyboard moveStoryboard = new Storyboard(); moveStoryboard.Duration = duration; myDoubleAnimationX.To = -(grid.ActualWidth);//到达 moveStoryboard.Children.Add(myDoubleAnimationX); Storyboard.SetTarget(myDoubleAnimationX, moveTransform); //故事版加入动画 Storyboard.SetTargetProperty(myDoubleAnimationX, "X"); rollStoryList.Add(moveStoryboard); moveStoryboard.Completed += new EventHandler <object>((senders, obj) => { grid_Roll.Children.Remove(grid); grid.Children.Clear(); grid = null; rollStoryList.Remove(moveStoryboard); moveStoryboard.Stop(); moveStoryboard = null; }); moveStoryboard.Begin(); }