I have a string containing some text (note the \\n
),
string mText = "Hello\nWorld";
When I apply this to a TextBlock
(generated by code) like this:
TextBlock tb = new TextBlock();
tb.Foreground = (Brush)App.Current.Resources["PhoneForegroundBrush"];
tb.FontSize = (double)App.Current.Resources["PhoneFontSizeMedium"];
tb.Margin = new Thickness(24, 32, 24, 12);
tb.TextWrapping = TextWrapping.Wrap;
tb.Text = mText;
I don't see the second line. Any ideas?
[UPDATE - Added the usage of this code]
I use this in showing a PopUp on the Screen:
// Create PopUp Content:
TextBlock tb = new TextBlock();
tb.Foreground = (Brush)App.Current.Resources["PhoneForegroundBrush"];
tb.FontSize = (double)App.Current.Resources["PhoneFontSizeMedium"];
tb.Margin = new Thickness(24, 32, 24, 12);
tb.TextWrapping = TextWrapping.Wrap;
tb.Text = pMessage;
Grid grid = new Grid();
grid.Background = (Brush)App.Current.Resources["PhoneAccentBrush"];
grid.Children.Add(tb);
grid.Width = page.ActualWidth;
// Create PopUp itself:
Popup popup = new Popup();
popup.Child = grid;
// Show PopUp:
SystemTray.BackgroundColor = (Color)App.Current.Resources["PhoneAccentColor"];
popup.IsOpen = true;
You could also add the following:
tb.Text = mText + Environment.NewLine;
or
tb.Text = mText + " " + " "
that seems to insert the <LineBreak/>
into.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.