Поделиться через


Where is RichTextBox in the Mango beta?

if you try using RichTextBox in the recently released Mango Beta tools, you might notice the control does not have a default control template applied to it.  [That means when you try to use it, you will see nothing but not get an error either]. 

This is a known issue for the beta.  To get around it, simply apply this current Style to the page (or the App.xaml) for your project .

 <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">
        <Setter.Value>
          <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}"/>
              </Border>
            </Grid>
          </ControlTemplate>
        </Setter.Value>
      </Setter>
    </Style>

Notice we are using an implicit style (yay for Silverlight 4 on the phone!! )

Another known issue with the current beta build is that images are not showing up in the rich textbox (they show up in the designer in Visual Studio/Blend )but not at run-time.  This is also fixed in later builds.  Still, the template above should be enough to get you rolling with RichTextBox.

Happy Windows Phone coding!!