在WPF中自动从左到右移动标签 [英] auto move a label left to right in WPF

查看:244
本文介绍了在WPF中自动从左到右移动标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我是WPF的新手我的问题是如何在WPF应用程序中自动从左到右移动标签





谢谢和问候

Indrajit

Hi
I am new to WPF my question is how to auto move a label left to right in WPF application


Thanks & regards
Indrajit

推荐答案

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.Window1xmlns:x =#unknown >



xmlns =http://schemas.microsoft.com/winfx/2006/xaml/presentation



xmlns:x = http://schemas.microsoft.com/winfx/2006/xaml



Title =Window1Height =500Width =700>



< canvas background =White>



< canvas margin =50 canvas.left =150canvas.top =100cliptobounds =Truename =canMainbackground =Redheight =100width =300>



< textblock margin =0,40fontsize =25name =tbmarquee>孟加拉国



< / canvas> ;



< / canvas>











从左到右选框:使用画布左侧属性



左选框:使用画布的右属性



对于向上选框:使用画布的底部属性



Fo r向下选框:使用画布的顶级属性











< textblock grid.row =2fontsize =22 name =txtScrolling>

< textblock.rendertransform>

< translatetransform x:name =translatexmlns:x =#unknown>

< textblock.triggers>

< eventtrigger routedevent =FrameworkElement.Loaded>

< beginstoryboard>

< storyboard repeatbehavior =Forever>

< doubleanimation>

From =1200To = - 1200

Storyboard.TargetName =翻译

Storyboard.TargetProperty =X

持续时间=0:0:9/>









这是滚动的文字
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">

xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

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

<canvas background="White">

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

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

</canvas>

</canvas>





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

Or



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




This is the Text to Scroll


这篇关于在WPF中自动从左到右移动标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆