question

MiguelCortsRodrguez-1654 avatar image
0 Votes"
MiguelCortsRodrguez-1654 asked ·

TextBlock Right TextAligment Doesn't work inside a ScrollViewer

Hi,

Im coding in XAML. Im trying to create a TextBlock inside a ScrollViewer with a Right Textaligment. but no matter what I put, when the text exceeds the width of the TextBlock, It always shows the text from the left to the right. Here is a piece of code in XAML:


<ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Disabled" Style="{StaticResource EstiloScrollViewer}" Margin="0 5 0 0">
<TextBlock TextAlignment="Right" HorizontalAlignment="Right" Name="operacion" Foreground="#FFC6C7C7" FontSize="25" FontFamily="Segoe UI Light"
Text="99999999999999999999999998745" />
</ScrollViewer>


The result is:

9770-pic1.png



If I put the same Code without the ScrollViewer the result is the next:

<TextBlock TextAlignment="Right" HorizontalAlignment="Right" Name="operacion" Foreground="#FFC6C7C7" FontSize="25" FontFamily="Segoe UI Light" Text="99999999999999999999999998745" Margin="20 0"/>

9871-pic2.png


windows-wpf
pic1.png (3.1 KiB)
pic2.png (3.9 KiB)
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

DaisyTian-MSFT avatar image
0 Votes"
DaisyTian-MSFT answered ·

Add a SizeChanged event for your ScrollView to Scroll it to the right when it's size changed:

 private void ScrollViewer_SizeChanged(object sender, SizeChangedEventArgs e)
         {
             double d = myScrollViewer.ActualWidth;
             myScrollViewer.ScrollToHorizontalOffset(d*d);
         }
· 1 · Share
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Really helpfull and easy to implement... Problem solved!

Thanks a lot!!

0 Votes 0 · ·