Click here to Skip to main content
15,796,456 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am new to WPF my question is how to auto move a label left to right in WPF application

Thanks & regards
Fredrik Bornander 7-Feb-13 4:10am    
Do you mean you want to animate it's position so that it moves to the left?
IndrajitDasgupat 8-Feb-13 0:30am    
I mean in C# windows application we are using time_Tick event below is code

private void timer1_Tick(object sender, EventArgs e)
label1.Location = new Point(label1.Location.X + 5, label1.Location.Y);

if(label1.Location.X > this.Width)
label1.Location = new Point(0 - label1.Width, label1.Location.Y);
Now how can I do same thing in WPF

1 solution

void Window1_Loaded(object sender, RoutedEventArgs e)


DoubleAnimation doubleAnimation = new DoubleAnimation();

doubleAnimation.From = -tbmarquee.ActualWidth;

doubleAnimation.To = canMain.ActualWidth;

doubleAnimation.RepeatBehavior = RepeatBehavior.Forever;

doubleAnimation.Duration = new Duration(TimeSpan.Parse("0 : 0 : 10"));

tbmarquee.BeginAnimation(Canvas.LeftProperty, doubleAnimation);


// xaml

<window x:class="MarqueText.Window1" xmlns:x="#unknown">



Title="Window1" Height="500" Width="700" >

<canvas background="White">

<canvas margin="50" canvas.left="150""100" cliptobounds="True" name="canMain" background="Red" height="100" width="300">

<textblock margin="0,40" fontsize="25" name="tbmarquee">Bangladesh



For Left to right marquee: use Left Property of Canvas

For right to left marquee: use Right Property of Canvas

For upward marquee: use Bottom Property of Canvas

For Downward marquee: use Top Property of Canvas


<textblock grid.row="2" fontsize="22" name="txtScrolling">
<translatetransform x:name="translate" xmlns:x="#unknown">
<eventtrigger routedevent="FrameworkElement.Loaded">
<storyboard repeatbehavior="Forever">
From="1200" To="-1200"
Duration="0 : 0 :9" />

This is the Text to Scroll
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900