我正在嘗試製作一個動畫,其中我抓住TextChanged事件並使新添加的字符從字體大小0淡出到由我設置的大小。設置WPF文本框中單個字符的字體大小
我有動畫工作,但是,當我鍵入一個新的字符時,文本框的整個內容會隨之改變,但我只想要按下的鍵。
這是我的代碼:
private void CreateTextboxAnimation(TextBox box)
{
// Info Needed By Control
double FontSize = box.FontSize;
//
DoubleAnimation Anim = new DoubleAnimation();
Anim.From = 0.0;
Anim.To = FontSize;
Anim.Duration = new Duration(TimeSpan.FromMilliseconds(100));
Anim.AutoReverse = false;
SB = new Storyboard();
SB.Children.Add(Anim);
Storyboard.SetTargetName(Anim, box.Name);
Storyboard.SetTargetProperty(Anim, new PropertyPath(TextBox.FontSizeProperty));
}
private Storyboard SB;
private void TestBox_TextChanged(object sender, TextChangedEventArgs e)
{
if (TestBox.IsLoaded == true)
{
SB.Begin(TestBox);
}
}
您最好的選擇可能是使用了'RichTextBox'。你將能夠操縱個人角色。 –