2010-11-23 147 views
0

我有容器与文本块内容。文本块文本将被更改为任何文本。我需要用动画改变容器的大小。什么是最好的办法呢?Silverlight宽度平滑动画

从: [世界你好文本] 到: [你好]

与动画。

回答

3

你应该从代码,当你更新TextBlock的文字动画容器的宽度:

// right before updating the text: 
textBlock.Text = "hello"; 
textBlock.UpdateLayout(); 
// animation is a DoubleAnimation 
animation.From = container.ActualWidth; 
animation.To = textBlock.ActualWidth; 
// storyBoard is a Storyboard that contains animation and targets container.Width 
storyBoard.Begin(); 

我怕你不仅可以用XAML做到这一点。