开发者

How do I get a toolbar for the Silverlight 4 RichTextBox?

开发者 https://www.devze.com 2022-12-27 04:36 出处:网络
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 j

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号