Line breaks in windowsphonetoolkit custom message box

96 views Asked by At

Using the windowsphonetoolkit how can one force line breaks in the message text to nicely format it. It appears that the stardard "\n" and "\n\r" line breaks do not work.

So something like:

This is the first line
and 
This is another line.

1

There are 1 answers

0
Łukasz Rejman On

You can achieve that by setting your message in Content property instead of Message. Then the message could be just a TextBlock where you can do whatever you want.

If you're doing your custom message box in XAML, the could look like this:

<toolkit:CustomMessageBox Caption="Caption" 
                          LeftButtonContent="ok"
                          RightButtonContent="cancel">
    <TextBlock Margin="12" 
               FontSize="{StaticResource PhoneFontSizeMedium}" 
               FontFamily="Segoe WP SemiLight">First line<LineBreak />Second line</TextBlock>
</toolkit:CustomMessageBox>

But you can also make it in code behind:

CustomMessageBox messageBox = new CustomMessageBox()
{
    Caption = "Caption",
    LeftButtonContent = "ok",
    RightButtonContent = "cancel",
    Content = new TextBlock()
    {
        Margin = new Thickness(12),
        FontSize = (double)Resources["PhoneFontSizeMedium"],
        FontFamily = new System.Windows.Media.FontFamily("Segoe WP SemiLight"),
        Text = "First line" + Environment.NewLine + "Second line",
    },
};
// messageBox.Show();

Result:
screenshot