I have a WPF text block that contains seven lines of text and has word wrap.
<TextBox TextWrapping="Wrap" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" MaxLines="7"/>
As you can see in the XAML above, the text is centered vertically and horizontally. When I print a short phrase that fits on one line, the text appears on the 4th line of the control, as expected, since VerticalContentAlignment is the "Center".
The text entered by the user is intended to be sent to a mobile device with a display that contains seven lines of text and uses "\ n" to transfer to the next line. The goal is that displaying text on a mobile device looks the same as displaying text in a TextBox control. At least how many lines of text, centering and line breaks.
Therefore, when the user finishes entering text into the TextBox control and clicks the "Send Message" button, some post-processing should be performed on the entered text before sending to the mobile device.
The text entered in the TextBox control must contain newline characters (\ n), where the text is wrapped to a new line in the TextBox control. For example, in cases where the control shows several lines of text, I copy the TextBox text and add a new line between the lines in which the TextBox control wrapped the lines of text entered by the user.
So, when the user clicks the "Send Message" button, this is the code that performs the mail processing:
public static String AddNewLineCharsToMessage(TextBox textBox) { String message = String.Empty; if (textBox == null) return message;
Given the above code, I expect the output for one line of text to look something like this: "\ n \ n \ n \ nFoo". However, the output is "\ nFoo \ nFoo \ nFoo \ nFoo". By setting a breakpoint in the code, I see that textBox.GetLineText (index) for indices 0 through 3 returns "Foo" for each index, although "Foo" is displayed only once in the TextBox control.
So, I really have two questions:
1) Why does GetLineText return a LineCount of 4 with each line having the same text when the user entered only one line of text (which fits on one line in a TextBox control)?
2) What is an easy way to get around this, save the entered text in the TextBox control center and send a text message to the remote device that will be displayed, as the user can see in the TextBox control?
Notes: I cannot just delete duplicate lines of text and replace them with "\ n", because the user could type the same text on multiple lines. Also, I could just align the entered text with a vertical top instead of a vertical center. I tested this, but does not give a true WYSIWIG experience.