I am attempting to use the WrapPanel and two TextBlocks to append an asterisk (*) to the left side of some text, allow the text to wrap, and force the text to be right aligned. I have successfully done so by creating a WrapPanel with the FlowDirection set to RightToLeft and adding my text, followed by the asterisk. However, if the text I use happens to have any non-alphanumeric characters at the end of the line it is inexplicably forced to the front of the line. I find this behavior to be very strange. I think it must be a bug in WPF and not intended behavior.
Example with Text = Normal Text (Other Text) :
Expected:
* Normal Text (Other
Text)
Actual:
* Normal Text (Other
(Text
Feel free to use the following sample code to recreate the issue for yourself. Simply put this in a window with Height and Width = 100, then type "Normal Text (Other Text)" in the TextBox. Or, set the Height and Width to anything you like and write enough text that it is forced to wrap the text, then add punctuation to the end.
Sample Code:
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<TextBox Name="input" />
<WrapPanel Grid.Row="2" FlowDirection="RightToLeft">
<TextBlock Text="{Binding ElementName=input, Path=Text}" TextWrapping="Wrap"/>
<TextBlock Text="*" Margin="0,0,3,0"/>
</WrapPanel>
</Grid>
So, my question(s).
- Is this a bug, or is this intended?
- If this is a bug, should I submit it to Microsoft in some way? How?
Since starting this post, I have decided to put the two TextBlocks in a two column grid instead. With the non-asterisk containing TextBlock configured to use a Right TextAlignment I meet all my requirements anyway. Still, I found this to be an interesting issue.