受限空间中的WPF Marquee文本动画

时间:2014-05-11 12:09:23

标签: c# wpf text marquee

我可以使用[DoubleAnimation]滚动文本但是      我想表现如下:

1.我有大网格和小画布

2.Text出现在画布右边缘

3.测试在画布左边消失

4.我喜欢只在画布上显示文字。不是网格

如何在C#中创建它?

这是图片链接

http://i.stack.imgur.com/Hmhho.jpg

1。 C#代码

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();

    }

2。 xaml代码

<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>

1 个答案:

答案 0 :(得分:0)

这是好方法

Panel.ZIndex = “1”

<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>