我开始在wpf中玩动画,我正在尝试以下方法:
My Title
My Title
e My Titl
le My Tit
tle My Ti
我的意思是标题将从左向右移动。
现在我有:
<TextBlock Name="MyWipedText"
Width="80"
FontSize="35"
Foreground="White"
Text="My Title" >
<TextBlock.Triggers>
<EventTrigger RoutedEvent="TextBlock.Loaded">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation
Storyboard.TargetName="MyWipedText"
Storyboard.TargetProperty="(TextBlock.Width)"
To="0.0" Duration="0:0:4"
AutoReverse="False" RepeatBehavior="Forever" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</TextBlock.Triggers>
</TextBlock>
答案 0 :(得分:0)
使用类似TextBlock的
<TextBlock x:Name="textBlock" Text="Hello, World. "/>
您可以使用DispatcherTimer轻松为文本设置动画:
public MainWindow()
{
InitializeComponent();
var timer = new DispatcherTimer { Interval = TimeSpan.FromSeconds(0.1) };
timer.Tick += (s, e) =>
{
var text = textBlock.Text;
var last = text.Length - 1;
textBlock.Text = text.Substring(last, 1) + text.Substring(0, last);
};
timer.Start();
}