First, you need to add ClipToBounds="True"
to you central StackPanel
to stop the text from showing after it leaves the bounds of the StackPanel
.
Secondly, the text stops at a 'certain distance' as you say because you told it to by setting the DoubleAnimation
to only move to -200
. We need to replace that with the actual value of the StackPanel.ActualWidth
property:
<DoubleAnimation To="{Binding ActualWidth, ElementName=UserContainer}"
Storyboard.TargetName="translate" Storyboard.TargetProperty="X" Duration="0:0:3"
AutoReverse="True" />
However, this moves the text to the right edge instead. I'm going to give this to you as an answer for now and if I can think of an easy way to reverse the direction of movement, I'll come back and edit it later.
UPADTE >>>
Ok, so the easiest thing to make the text move left is to implement a simple Converter
:
public class AdditiveInverseDoubleConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value == null || value.GetType() != typeof(double) && targetType != typeof(double)) return false;
return -(double)value;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value == null || value.GetType() != typeof(double) && targetType != typeof(double)) return false;
return -(double)value;
}
}
Then change your XAML:
<DoubleAnimation To="{Binding ActualWidth, ElementName=UserContainer, Converter={
StaticResource AdditiveInverseDoubleConverter}}" Storyboard.TargetName="translate"
Storyboard.TargetProperty="X" Duration="0:0:3" AutoReverse="True" />
Don't forget to add the XML Namespace:
xmlns:Converters="clr-namespace:WpfApplication1.Converters"
And Resource
:
<Window.Resources>
<Converters:AdditiveInverseDoubleConverter x:Key="AdditiveInverseDoubleConverter" />
</Window.Resources>
UPDATE 2 >>>
Ah, I just worked it out... the TextBlock
is cut off because it won't fit into the StackPanel
otherwise... making the StackPanel
bigger makes more text appear. However, the answer is to not use the StackPanel
and use a Canvas
instead... this shows all of the text.