-1

I'm working on an UWP app in C# and xaml and I want to display an infinite continuous text scrolling (the same text scrolling continuously without any blank).

I tried first with embedding a textblock in a scrollviewer but when the text has gone through the grid, it starts again from the beginning so there is a blank.

So I tried and succeeded in scrolling a textBlock with a timer, but for now it's the same : when the text has scrolled it starts from the beginning while I want to make it continuous (like the tv news).

I think that what I need is 2 textBlock one following the other?

Here is my xaml code (with timer)

<TextBlock Name="SongTextBlock" 
 Foreground="White" FontSize="20px" 
 Text=" "     
 TextWrapping="NoWrap" 
 Loaded="scrollText_Loaded" 
 Unloaded="scrollText_Unloaded" />

and the C#

private void scrollText_Loaded(object sender, RoutedEventArgs e)
{
    //on récupère la largeur du conteneur principal de notre appli
    double mainGridWidth = MainGrid.ActualWidth;
    //on initialise la position du textBlock (en dehors de la page)
    SongTextBlock.Margin = new Thickness(mainGridWidth, 0, 0, 0);

    timer.Tick += (ss, ee) =>
    {
        if (timer.Interval.Ticks == 300)
        {
            SongTextBlock.Margin = new Thickness(SongTextBlock.Margin.Left - 5, 0, 0, 0);
            if (SongTextBlock.Margin.Left <= -mainGridWidth) SongTextBlock.Margin = new Thickness(mainGridWidth, 0, 0, 0);
        }
    };
    timer.Interval = new TimeSpan(300);
    timer.Start();
}

private void scrollText_Unloaded(object sender, RoutedEventArgs e)
{
    timer.Stop();
}
Acidy
  • 13
  • 5
  • It's not clear what you're asking. Please be more specific. Provide a good [mcve]. Explain _precisely_ what that code does now, and what you want it to do instead. – Peter Duniho Aug 24 '16 at 17:42
  • Possible duplicate of [c# UWP autoscrolling text](http://stackoverflow.com/questions/38433555/c-sharp-uwp-autoscrolling-text) – ZORRO Aug 25 '16 at 17:31
  • Hi, sorry for not having been clear, english is not my first language. I edit my original post to be more specific. Before posting I tried the c# UWP autoscrolling text solution but it is not what I want to do since there is a blank when the text has scrolled and before it scrolls again. – Acidy Aug 26 '16 at 09:07
  • @Acidy, you mean there is a blink when the text has scrolled and before it scrolls again? You want it looks like a loop one? – Grace Feng Aug 26 '16 at 09:48
  • @Grace Feng, sorry I didn't see your message sooner. Yes, This exactly what I want, I want it to loop without a blink. – Acidy Sep 11 '16 at 12:59

1 Answers1

0

What you need is to put your TextBlock inside of a ScrollViewer, so can the Text be scrolled when time ticks.

You can refer to my another case: c# UWP autoscrolling text, there I wrote a demo for this scroll-able text.

And here is another case about modifying the layout of ScrollViewer and TextBlock together so will it looks like a whole one: TextBox sizing inside ScrollView with horizontal scroll.

Community
  • 1
  • 1
Grace Feng
  • 16,564
  • 2
  • 22
  • 45
  • Hi, thanks for your reply, but as I say above, I've already tried this solution and it's not exactly what I want to do. – Acidy Aug 26 '16 at 09:08