[英]wpf - Dynamically Moving TextBlock
I have a TextBlock that I create during run-time: 我在运行时创建了一个TextBlock:
TextBlock firstBlock = new TextBlock();
firstBlock.Text = "Mary Joe";
firstBlock.Margin = new Thickness(0, 0, -1500, 0);
firstBlock.FontSize = 72;
firstBlock.TextAlignment = TextAlignment.Center;
firstBlock.Foreground = Brushes.Red;
myGrid.Children.Add(firstBlock);
I want to be able to move the TextBlock down the Y-axis smoothly. 我希望能够将TextBlock平稳地沿Y轴向下移动。 I've thought to use DoubleAnimation, but I couldn't find a property to alter in order to move it.
我曾经考虑过使用DoubleAnimation,但是我找不到要更改的属性来移动它。 I would also like to make the text smaller as it goes downwards (kind of like a reverse Stars Wars Credits, but no 3D).
我还想使文本向下变小(有点像反向的《星际大战》,但没有3D)。 I know this stuff is pretty simple to make in xaml, but I want to be able to call the animation at certain times and add new text each time in the blocks.
我知道用xaml制作东西很简单,但是我希望能够在特定时间调用动画并每次在块中添加新文本。 I've searched around a lot to no avail.
我搜索了很多无济于事。 I figured I would post here to see if smart people could help me :).
我想我会在这里发布,看看聪明的人是否可以帮助我:)。
You can use a TranslateTransform on the TextBlock to move it. 您可以在TextBlock上使用TranslateTransform来移动它。 Use a double animation on the Y property.
在Y属性上使用双重动画。
For the FontSize use another double animation to shrink the value. 对于FontSize,使用另一个double动画来缩小值。 Put them both in a Storyboard and you can run them at the same time.
将它们都放在情节提要中,您可以同时运行它们。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.