RichTextBox in Windows Phone 7.1 or Mango

RichTextBox control is one of the most welcome controls in Beta release of Windows Phone 7.1 or Mango phone.

Beta version of RichTextBox control has come with many limitations  Sad smile

  • It is Read Only
  • Control does not appear in tool box
  • There is no default style.

There are two usual ways to add RichTextBox, one directly add on XAML as below,



Another in code as below,


If you just add RichTextBox in XAML and run application, surprisingly you will not get rendered RichTextBox on page Sad smile . This is due to absence of default style for RichTextBox.

So to work with RichTextBox we need to add Default Style for RichTextBox.  In below App.Xaml , I have added default style for RichTextBox.



    <!--Application Resources-->

        <Style TargetType="RichTextBox">
            <Setter Property="FontSize" Value="{StaticResource PhoneFontSizeNormal}" />
            <Setter Property="Foreground" Value="{StaticResource PhoneForegroundBrush}" />
            <Setter Property="Background" Value="Transparent" />
            <Setter Property="BorderBrush" Value="Transparent" />
            <Setter Property="BorderThickness" Value="0"/>
            <Setter Property="HorizontalContentAlignment" Value="Stretch" />
            <Setter Property="VerticalContentAlignment" Value="Center" />
            <Setter Property="Padding" Value="0" />
            <Setter Property="Template">
                    <ControlTemplate TargetType="RichTextBox">
                        <Grid Background="Transparent">
                            <Border Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Margin="{StaticResource PhoneHorizontalMargin}">
                                <ContentControl x:Name="ContentElement" HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}" Padding="{TemplateBinding Padding}"/>

        <!--Required object that handles lifetime events for the application-->
            Launching="Application_Launching" Closing="Application_Closing"
            Activated="Application_Activated" Deactivated="Application_Deactivated"/>




After adding style for RichTextBox, on running you will get RichTextBox on phone as below,


To add button in RichTextBox , we need to put Button control inside InlineUIContainer like below .


To add an Undeline text we need to put text in Underline  tag



To add Image in RichTextBox we need to put Image in InlineUIContainer



After adding RichTextBox with different paragraphs containing Button , Image , Bold Text and Underlined text XAML would be as below ,


    mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="768"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    SupportedOrientations="Portrait" Orientation="Portrait"

    <!--LayoutRoot is the root grid where all page content is placed-->
    <Grid x:Name="LayoutRoot" Background="Transparent">
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>

        <!--TitlePanel contains the name of the application and page title-->
        <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
            <TextBlock x:Name="ApplicationTitle" Text="MY APPLICATION" Style="{StaticResource PhoneTextNormalStyle}"/>
            <TextBlock x:Name="PageTitle" Text="page name" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>

        <!--ContentPanel - place additional content here-->
        <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
            <RichTextBox x:Name="rtxtbox" Margin="0,-84,0,0">
                    <Bold Foreground="BLUE">Hey I am Blue and Bold !</Bold>
                        <Image Source="Penguins.jpg" />
                <Paragraph >
                    Dhananjay Kumar is here on DebugMode
                <Paragraph >
                            Content="RichTextBox Button "
                             Click="btnRch_Click" />
                        <Image Source="Penguins.jpg" Height="20" Width="30"/>
                    <Underline>I am UnderLined</Underline>






When you run phone application, you should get output as below,




In XAML if you will notice there are two paragraphs one for Button and one for Image. But in output those Image and Button is not getting displayed. In next post I would discuss on the same. And I if you get solution of this problem before me please write to me about your investigation  Smile

Thanks  for reading .

5 responses to “RichTextBox in Windows Phone 7.1 or Mango”

  1. […] RichTextBox in Windows Phone 7.1 or Mango | DEBUG MODE…… […]

  2. […] RichTextBox in Windows Phone 7.1 or Mango (Dhananjay Kumar) […]

  3. […] RichTextBox in Windows Phone 7.1 or Mango – Dhananjay Kumar […]

  4. Is there any way to set RichTextBox content in code behind?

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Create a website or blog at