I can scroll text with TranslateTransform
but when the animation is close to finishing I'd like it to begin again. Like a snake :)
This is what I've got:
<StackPanel Orientation="Horizontal" Margin="0,0,0,0">
<StackPanel.RenderTransform>
<TranslateTransform x:Name="transferCurreny" X="-40"/>
</StackPanel.RenderTransform>
<StackPanel.Triggers>
<EventTrigger RoutedEvent="StackPanel.Loaded">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation From="0" To="-900" Duration="00:00:10"
Storyboard.TargetProperty="X"
Storyboard.TargetName="transferCurreny"
RepeatBehavior="Forever"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</StackPanel.Triggers>
<TextBlock FontSize="25" x:Name="txtKron" Margin="10,0,7,0"/>
</StackPanel>
This is what I'd like:
Something like this should do the trick.
You can add a
Canvas
to theStackPanel
with 2TextBlocks
one set to position 0 and one set to theActualWidth
of theStackPanel
, then when the first block of text goes offscreen the other block will come into view.The reason I used
Canvas
is becauseCanvas
is the only element that actually supportsClipToBounds="false"
this allows the 2ndTextBlock
to be visible even if its placed outside the bounds of theCanvas
itselfWe also need a
IValueConverter
to get the correct negative value if you want to scroll from right to left.I also added event trigger on
SizeChanged
so if the window is resized the animation values will update correctly.Code:
Xaml:
Result:
Edit: Left to Right
The code in above answer does not produce continuous scroll. Here is the code for continuous smooth scroll.
XAML:
VB Code Behind:
Exteding the answer of sa_ddam213, this is a revise of the first animation(Right to Left). This will work for long strings. :)