views:

331

answers:

1

I put the RichTextBox in my Silverlight App. Do I have to create my own set of buttons to use it? I want to have a standard set of editing buttons for the text box.

+3  A: 

Unfortunately it's just the textbox not a whole suite of controls too like the toolbar, which is something you get with commercial WPF/Silverlight rich text boxes.

You tie your buttons up to format code as shown here:

//Set Bold formatting to selected content
private void BtnBold_Click(object sender, RoutedEventArgs e)
{
    object o = MyRTB.Selection.GetPropertyValue(TextElement.FontWeightProperty);
    if (o.ToString() != "Bold")
        MyRTB.Selection.ApplyPropertyValue(TextElement.FontWeightProperty, FontWeights.Bold);


}
//<SnippetItalic>
//Set Italic formatting to selected content
private void BtnItalic_Click(object sender, RoutedEventArgs e)
{
    object o = MyRTB.Selection.GetPropertyValue(TextElement.FontWeightProperty);
    if (o.ToString() != "Italic")
        MyRTB.Selection.ApplyPropertyValue(TextElement.FontStyleProperty, FontStyles.Italic);


}

//Set Underline formatting to selected content
private void BtnUnderline_Click(object sender, RoutedEventArgs e)
{
    object o = MyRTB.Selection.GetPropertyValue(TextElement.FontWeightProperty);
    if (o.ToString() != "Underline")
        MyRTB.Selection.ApplyPropertyValue(TextElement.TextDecorationsProperty, TextDecorations.Underline);
}
Chris S