How do I get the toolbar for Silverlight 4 RichTextBox?

I have put RichTextBox in my Silverlight application. Do I have to create my own set of buttons to use it? I want to have a standard set of edit buttons for a textbox.

+2


a source to share


2 answers


Unfortunately, this is just a textbox and not a whole set of controls like the toolbar you get with commercial WPF / Silverlight textboxes.

You bind your buttons prior to code formatting 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);
}

      

+4


a source


To provide your Silverlight application with a Mircosoft Office style formatting toolbar, check out the MSDN Silverlight Text Editor.



+1


a source







All Articles