C# 限制空间中的WPF字幕文本动画
我可以使用[DoubleAnimation]滚动文本,但是 我想展示如下: 1.我有大网格和小画布 2.文本出现在画布右边缘 3.测试在画布左边缘消失 4.我喜欢只在画布上显示文本。非网格 如何在C#中制作此文件 这是图像链接 一,。C#代码 二,。xaml代码C# 限制空间中的WPF字幕文本动画,c#,wpf,text,marquee,C#,Wpf,Text,Marquee,我可以使用[DoubleAnimation]滚动文本,但是 我想展示如下: 1.我有大网格和小画布 2.文本出现在画布右边缘 3.测试在画布左边缘消失 4.我喜欢只在画布上显示文本。非网格 如何在C#中制作此文件 这是图像链接 一,。C#代码 二,。xaml代码 这是个好办法 Panel.ZIndex=“1” private void animation() { Storyboard sb = new Storyboard(); DoubleA
这是个好办法
Panel.ZIndex=“1”
private void animation()
{
Storyboard sb = new Storyboard();
DoubleAnimation moveLeft = new DoubleAnimation();
moveLeft.From = Canvas.Width;
moveLeft.To = -tbxText.Width;
moveLeft.Duration = new Duration(TimeSpan.FromSeconds(3));
moveLeft.RepeatBehavior = RepeatBehavior.Forever;
Storyboard.SetTarget(moveLeft, tbxText);
Storyboard.SetTargetProperty(moveLeft, new PropertyPath(Canvas.LeftProperty));
moveLeft.EasingFunction = new CircleEase() { EasingMode = System.Windows.Media.Animation.EasingMode.EaseOut };
sb.Children.Add(moveLeft);
sb.Begin();
}
<Grid HorizontalAlignment="Left" Height="59" Margin="42,33,0,0" VerticalAlignment="Top" Width="255" Background="#FFC9F594">
<Canvas x:Name="Canvas" HorizontalAlignment="Left" Height="59" VerticalAlignment="Top" Width="255">
<TextBox x:Name="tbxText" Height="34" Canvas.Left="10" TextWrapping="Wrap" Text="Test Test Test Test" Canvas.Top="6" Width="196" Background="{x:Null}" BorderBrush="{x:Null}" FontSize="20"/>
</Canvas>
</Grid>
<Grid Panel.ZIndex="1" HorizontalAlignment="Left" Height="55" Margin="114,83,0,0" VerticalAlignment="Top" Width="266">
<Canvas x:Name="Canvas" HorizontalAlignment="Left" Height="59" VerticalAlignment="Top" Width="255" Margin="1,0,0,-4">
<TextBox x:Name="tbxText" Height="34" Canvas.Left="10" TextWrapping="Wrap" Text="Test Test Test Test" Canvas.Top="6" Width="196" Background="{x:Null}" BorderBrush="{x:Null}" FontSize="20"/>
</Canvas>
</Grid>