Ok, I have just run into something that is really catching me off-guard.
I was helping a fellow developer with a couple of unrelated questions and in his project he
Trying to animate the TextBox manually ....
var timeline = new StringAnimationUsingKeyFrames();
timeline.KeyFrames.Add(new DiscreteStringKeyFrame("Goodbye", KeyTime.FromTimeSpan(new TimeSpan(0,0,1))));
textControl.BeginAnimation(TextBox.TextProperty, timeline);
...reveals a more useful error message. The last line fails with the following ArgumentException
:
'Text' property is not animatable on 'System.Windows.Controls.TextBox' class because the IsAnimationProhibited flag has been set on the UIPropertyMetadata used to associate the property with the class.
Parameter name: dp
The documentation of UIPropertyMetadata.IsAnimationProhibited says:
In general, the default dependency properties available in the Windows Presentation Foundation (WPF) framework implementation APIs can be animated. You might set this property to true in the metadata of your own custom dependency property to disable animations on it.
Apparently, the designers of the WPF library decided that animating the Text
depdendency property of a TextBox is not a good idea and explicitly disabled it.
So, that's the technical answer as to why this property cannot be animated. Why did they disable it? I have no idea...
PS: A quick look at the static constructors of TextBox
, TextBoxBase
and Control
with Reflector reveals that Text
is the only TextBox dependency property that cannot be animated.