我将RichTextBox放在我的Silverlight应用程序中。我是否必须创建自己的按钮组才能使用它?我想为文本框设置一组标准的编辑按钮。
答案 0 :(得分:4)
不幸的是,它只是文本框而不是整个控件套件,就像工具栏一样,这是商业WPF / Silverlight富文本框所能提供的。
您将按钮绑定到格式代码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);
}
答案 1 :(得分:1)
要为您的Silverlight应用提供具有Microsoft Office风格的格式工具栏,请查看MSDN Silverlight Text Editor example.