TextBlock WPF Overflow Text Left

As a background, I have a very long identifier that is too long to display in the given TextBlock area. The interesting part of the identifier is the end, that is, the rightmost part.

What I would like to do is to have a TextBlock, and not overflow the text on the right and cut off the right-most part, overflow the left and cut off the very left part.

This is assigned an identifier 123456and a text block with enough space to hold four characters so that the TextBlock displays 3456, rather than 1234, by default.

I could manually crop my id to display, but assuming the variable font size is not perfect. So, is there a way to get WPF to change the direction of the overflow?

+3
source share
4 answers

Is this the effect you are trying to get? It sounds like this:

<Page
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  <StackPanel Width="200">  
      <TextBlock Background="Honeydew" HorizontalAlignment="Right">
        The quick brown fox jumped over the lazy dog back
      </TextBlock>
    </StackPanel>
</Page>
+4
source

You just need to set the following attribute FlowDirection = "RightToLeft" in XAML for TextBox

+4
source

If you also want to show the full text when the user hovers over the cropped TextBlock, this is a bit complicated, but there is a way .

+2
source

To show all the text when the user hangs over the TextBox, just bind the ToolTip to the Text property of the TextBox:

ToolTip="{Binding RelativeSource={RelativeSource Self}, Path=Text}"
+1
source

Source: https://habr.com/ru/post/1736436/


All Articles