private void AutoCheck() { lock (_checkLock) { if (_storyboard != null) { switch (QueueStrategy) { case QueueStrategy.None: _storyboard.Completed -= Storyboard_Completed; _storyboard.Stop(); break; default: return; } } if (Dequeue(out string text)) { _textBlock.Text = text; MeasureText(text); } else if (!AutoRepeat) { return; } _storyboard = CreateStoryboard(); _storyboard.Completed += Storyboard_Completed; _textBlock.BeginStoryboard(_storyboard); } }
private void TextBlock_TargetUpdated(object sender, DataTransferEventArgs e) { TextBlock block = (TextBlock)e.Source; if (block.Text.Length > 1) { Storyboard newBoard = new Storyboard(); newBoard.FillBehavior = FillBehavior.Stop; newBoard.Duration = TimeSpan.FromSeconds(1); int effectCount = block.TextEffects.Count; int textLength = block.Text.Length; double letterPercent = 1.0 / (textLength + effectCount); for (int i = 0; i < effectCount; ++i) { Int32AnimationUsingKeyFrames positionCount = new Int32AnimationUsingKeyFrames(); positionCount.BeginTime = TimeSpan.Zero; Storyboard.SetTargetProperty(positionCount, new PropertyPath(string.Format("(TextElement.TextEffects)[{0}].(TextEffect.PositionCount)", i))); if (i > 0) { KeyTime startKeyTime = KeyTime.FromPercent((i - 1) * letterPercent); positionCount.KeyFrames.Add(new DiscreteInt32KeyFrame(0, startKeyTime)); } KeyTime moveCountKeyTime = KeyTime.FromPercent(i * letterPercent); positionCount.KeyFrames.Add(new DiscreteInt32KeyFrame(1, moveCountKeyTime)); KeyTime endCountKeyTime = KeyTime.FromPercent((textLength + i) * letterPercent); positionCount.KeyFrames.Add(new DiscreteInt32KeyFrame(0, endCountKeyTime)); newBoard.Children.Add(positionCount); Int32AnimationUsingKeyFrames positionStart = new Int32AnimationUsingKeyFrames(); positionStart.BeginTime = TimeSpan.Zero; Storyboard.SetTargetProperty(positionStart, new PropertyPath(string.Format("(TextElement.TextEffects)[{0}].(TextEffect.PositionStart)", i))); for (int j = 0; j < textLength; ++j) { KeyTime nextStartTime = KeyTime.FromPercent((j + i) * letterPercent); DiscreteInt32KeyFrame nextFrame = new DiscreteInt32KeyFrame(j, nextStartTime); positionStart.KeyFrames.Add(nextFrame); } newBoard.Children.Add(positionStart); } block.BeginStoryboard(newBoard, HandoffBehavior.SnapshotAndReplace, false); } }
private void AddMessage(string text) { if (messageTextBlocks.Count <TextBlock>(t => t.Opacity == 0.0) == messageTextBlocks.Count) { messageTextBlocks.Clear(); MessageContainerGrid.Children.Clear(); } TextBlock tb; tb = new TextBlock(); tb.Style = (Style)App.Current.Resources["MessageTextBlock"]; tb.Margin = new Thickness(0, 0, 20, 20 + (messageTextBlocks.Count * 50)); tb.Text = text; MessageContainerGrid.Children.Add(tb); messageTextBlocks.Add(tb); tb.BeginStoryboard((Storyboard)App.Current.Resources["FadeOut"]); return; }