WPF Бегущая строка

Вариант раз

Canvas x:Name="Canvas" Background="Transparent" Height="25"
                VerticalAlignment="Top">
            <TextBlock Margin="0,7,0,0" VerticalAlignment="Bottom" FontSize="15"  FontWeight="Bold" Foreground="#555"
                       Text="Тестовый текст" Canvas.Right="0">
                <TextBlock.Triggers>
                    <EventTrigger RoutedEvent="TextBlock.Loaded">
                        <EventTrigger.Actions>
                            <BeginStoryboard>
                                <Storyboard>
                                    <DoubleAnimation Storyboard.TargetProperty="(Canvas.Left)" From="1300" To="-750" 
                                                     Duration="0:0:15" RepeatBehavior="Forever"/>
                                </Storyboard>
                            </BeginStoryboard>
                        </EventTrigger.Actions>
                    </EventTrigger>
                </TextBlock.Triggers>
            </TextBlock>
        </Canvas>

http://axedeos.blogspot.ru/2012/11/wpf.html

Вариант два, с заданием в коде и с паузой

<Window x:Class="TestCode.StopAnimationWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="TestCode"
    >
  <StackPanel>
    <Rectangle Name="rect" Height="100" Fill="Red" Stroke="Green" StrokeThickness="1" Width="5"/>
    <StackPanel Orientation="Horizontal">
      <Button Width="100" Height="30" Content="Start" Click="StartAnimation"/>
      <Button Width="100" Height="30" Content="Pause" Click="PauseAnimation"/>
      <Button Width="100" Height="30" Content="Resume" Click="ResumeAnimation"/>
      <Button Width="100" Height="30" Content="Stop" Click="StopAnimation"/>
    </StackPanel>
    </StackPanel>
</Window>
 
public partial class StopAnimationWindow : System.Windows.Window
{
    AnimationClock clock;
    public StopAnimationWindow()
    {
        InitializeComponent();
    }
 
    private void StartAnimation(Object sender, RoutedEventArgs e)
    {
        DoubleAnimation animation = new DoubleAnimation();
        animation.Duration = new Duration(TimeSpan.FromSeconds(5));
        animation.To = 500d;
        animation.From = 0d;
        clock = animation.CreateClock();
        rect.ApplyAnimationClock(Rectangle.WidthProperty, clock);
    }
 
    private void PauseAnimation(Object sender, RoutedEventArgs e)
    {
        clock.Controller.Pause();
    }
 
    private void ResumeAnimation(Object sender, RoutedEventArgs e)
    {
        clock.Controller.Resume();
    }
 
    private void StopAnimation(Object sender, RoutedEventArgs e)
    {
        clock.Controller.Stop();
    }
}

http://social.msdn.microsoft.com/Forums/vstudio/en-US/5eb35986-4666-43f4-9e88-e940bf464ff5/how-to-pause-animation

Оставить комментарий


Примечание - Вы можете использовать эти HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>