Here are my TextBlock
s:
<StackPanel Orientation="Horizontal" Margin="0,3,0,0">
<TextBlock Text="6 or more characters, at least one letter and a number, " FontFamily="Segoe UI" Foreground="#000000" FontSize="13"/>
<TextBlock Text="no symbols" FontFamily="Segoe UI" Foreground="#000000" FontSize="13"/>
</StackPanel>
And here is the output (screen shot):
Why does TextBlock
trim ending spaces? However, it works fine when there are leading spaces.
It looks like xml:space="preserve"
should do the trick (see Preserving Whitespace in XAML) but that doesn't seem to be working in a Windows Store app (it does in WPF).
If you use the non-breaking space character  
it does work
<TextBlock Text="6 or more characters, at least one letter and a number,       " ....
I suppose you could try building a converter on the Text
property to check for trailing spaces and replace with non-breaking spaces - presuming the truncation that's happening doesn't occur too early.
Solved with <Run />
in a <TextBlock />.
.
<StackPanel Orientation="Horizontal" Margin="0,3,0,0">
<TextBlock FontFamily="Segoe UI" Foreground="#000000" FontSize="13">
<Run Text="6 or more characters, at least one letter and a number, " />
<Run Text="no symbols" />
</TextBlock>
</StackPanel>
And word wrapping still works
<StackPanel Orientation="Horizontal" Margin="0,3,0,0">
<TextBlock FontFamily="Segoe UI" Foreground="#000000" FontSize="13"
Width="200" TextWrapping="Wrap">
<Run Text="6 or more characters, at least one letter and a number, " />
<Run Text="no symbols" />
</TextBlock>
</StackPanel>
I would easily use Jim's solution (#160;) if wrapping was not an issue.
In your mind please think about how HTML handles and preserves spaces. This is also how XAML handles and preserves spaces. You would think, of course, that inside a TextBlock it would be more literally handled, huh? Well, it is what it is. At least there's a solution.
Try use xml:space="preserve"
:
<StackPanel Orientation="Horizontal" Margin="0,3,0,0">
<TextBlock xml:space="preserve" Text="6 or more characters, at least one letter and a number, " FontFamily="Segoe UI" Foreground="#000000" FontSize="13"/>
<TextBlock xml:space="preserve" Text="no symbols" FontFamily="Segoe UI" Foreground="#000000" FontSize="13"/>
</StackPanel>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With