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