我正在尝试制作一个动画,其中我抓住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'。你将能够操纵个人角色。 –