How do I get a toolbar for the Silverlight 4 RichTextBox?
I put the RichTextBox in my Silverlight App. D开发者_运维问答o 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.
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);
}
To give your Silverlight app a formatting toolbar with a Mircosoft Office-style feel, check out the MSDN Silverlight Text Editor example.
精彩评论