locked
(WP8.1)textbox文字超出显示区域如何自动滚动显示? RRS feed

  • 问题

  • 如题,

    文字长度超过textbox文本框,能不能让其自动滚动显示超出区域的文字;

    或者用的是textblock控件?

    2016年2月21日 11:19

答案

  • 您好,

    这种效果可以考虑用动画去实现,你需要借助外层容器,比如canvas。

    我的例子是用TextBlock实现的,你可以尝试用TextBox:

    <Page.Resources>
            
            <Storyboard x:Name="Storyboard2" RepeatBehavior="Forever">
                <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.TranslateX)" Storyboard.TargetName="marquee">
                    <EasingDoubleKeyFrame KeyTime="0" Value="0"/>
                    <EasingDoubleKeyFrame KeyTime="0:0:3" Value="-370"/>
                    <EasingDoubleKeyFrame KeyTime="0:0:6" Value="-13.75"/>
                </DoubleAnimationUsingKeyFrames>
                
            </Storyboard>
        </Page.Resources>
    
        <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
            <Canvas Width="150" >
                <TextBlock Name="marquee" Text="Sample Marquee abcdefghijklmnopqrst" RenderTransformOrigin="0.5,0.5" >
                    <TextBlock.RenderTransform>
                        <CompositeTransform/>
                    </TextBlock.RenderTransform>
                </TextBlock>
                <Button Width="100" Height="50" Content="Marquee" Click="Button_Click" Canvas.Left="168" Canvas.Top="168" />
            </Canvas>
    
        </Grid>
    private void Button_Click(object sender, RoutedEventArgs e)
            {
                Storyboard2.Begin();
            }
    另外一种,你可以考虑传统的C#编程方式去实现,可以借助Dispatcher.Timer类定时去移动文本框中的字符。


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    2016年2月24日 6:56

全部回复

  • 您好,

    >>"让其自动滚动显示超出区域的文字"

    我不是很明白你的意思,你是想让超出部分的文字自动换行显示,还是其他的什么效果,还请描述清楚。


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    2016年2月23日 8:05
  • 不是自动换行,

    就像跑马灯那样,字体从右向左移动,将未显示的字体显示出来,之前显示过的字逐步向左溢出隐藏;

    2016年2月23日 11:21
  • 您好,

    这种效果可以考虑用动画去实现,你需要借助外层容器,比如canvas。

    我的例子是用TextBlock实现的,你可以尝试用TextBox:

    <Page.Resources>
            
            <Storyboard x:Name="Storyboard2" RepeatBehavior="Forever">
                <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.TranslateX)" Storyboard.TargetName="marquee">
                    <EasingDoubleKeyFrame KeyTime="0" Value="0"/>
                    <EasingDoubleKeyFrame KeyTime="0:0:3" Value="-370"/>
                    <EasingDoubleKeyFrame KeyTime="0:0:6" Value="-13.75"/>
                </DoubleAnimationUsingKeyFrames>
                
            </Storyboard>
        </Page.Resources>
    
        <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
            <Canvas Width="150" >
                <TextBlock Name="marquee" Text="Sample Marquee abcdefghijklmnopqrst" RenderTransformOrigin="0.5,0.5" >
                    <TextBlock.RenderTransform>
                        <CompositeTransform/>
                    </TextBlock.RenderTransform>
                </TextBlock>
                <Button Width="100" Height="50" Content="Marquee" Click="Button_Click" Canvas.Left="168" Canvas.Top="168" />
            </Canvas>
    
        </Grid>
    private void Button_Click(object sender, RoutedEventArgs e)
            {
                Storyboard2.Begin();
            }
    另外一种,你可以考虑传统的C#编程方式去实现,可以借助Dispatcher.Timer类定时去移动文本框中的字符。


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    2016年2月24日 6:56