wpf 如何在wpf中将文本制作为选框

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20145212/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 10:06:05  来源:igfitidea点击:

How to make text as marquee in wpf

c#wpf

提问by Sanjay

Here I have code to scroll the text in wpf using Translate transform as

在这里,我有代码可以使用 Translate transform as 在 wpf 中滚动文本

   <TextBlock x:Name="_box" FontSize="64"  Text="lorem ipsum">
    <TextBlock.RenderTransform>

        <TranslateTransform x:Name="AnimatedTranslateTransform" X="0" Y="0" />
    </TextBlock.RenderTransform>
    <TextBlock.Triggers>
        <EventTrigger RoutedEvent="TextBlock.Loaded">
            <BeginStoryboard>
                <Storyboard>
                    <DoubleAnimation
                Storyboard.TargetName="AnimatedTranslateTransform" 
                Storyboard.TargetProperty="X"
                From="-300" To="300" Duration="0:0:5" 
                AutoReverse="True" RepeatBehavior="Forever" />
                </Storyboard>
            </BeginStoryboard>
        </EventTrigger>
    </TextBlock.Triggers>
</TextBlock>

How to write this code programmtically in wpf using translate transform in c#, please help me any one. i tried but strucked at textblock to add translate transform in render transform.

如何使用 c# 中的翻译转换在 wpf 中以编程方式编写此代码,请帮助我。我尝试过但在 textblock 中遇到了在渲染变换中添加翻译变换的问题。

回答by Monika

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

    }

Link:

关联:

http://weblogs.asp.net/razan/archive/2009/10/01/creating-marquee-scrolling-text-in-wpf.aspx

http://weblogs.asp.net/razan/archive/2009/10/01/creating-marquee-scrolling-text-in-wpf.aspx