zoukankan      html  css  js  c++  java
  • Silverlight: RichTextBox的简单学习

    RichTextBox的简单使用

    其实在Silverlight 4 中的sample中已经有一个很漂亮的名叫TextEditor的RichTextBox控件,

    Run Silverlight TextEditor

    Download the Sample

    以下是我自己简单封装的一个RichEditor,返回的是一个UIElement.

    1.  效果图

       

    2.  调用方法    

    RichEditor 调用代码
    RichEditor editor = new Controls.RichEditor();
    //根据需要设置是否显示操作条
    editor.IsDiplayClipboardBar = System.Windows.Visibility.Visible;
    editor.IsDiplayImageBar
    = Visibility.Visible;
    editor.IsDiplayParagraphBar
    = Visibility.Visible;
    AutoGrid element
    = editor.GenerateRichEditor();

    TaskDialog dialog
    = new TaskDialog()
    {
    Content
    = new Border
    {
    Child
    = new AutoGrid(2,80,700)
    {
    HorizontalAlignment
    = System.Windows.HorizontalAlignment.Left,
    Children
    = {
    (
    new TextBlock(){Text = "Title:"}),(new TextBox()),
    (
    new TextBlock(){Text = "SubTitle:"}),(new TextBox()).Do(o => {o.Margin = new Thickness (0,5,0,5);}),
    (
    new TextBlock(){Text = "Author:"}),(new TextBox()),
    (
    new TextBlock(){Text = "Content:"}).GridRowSpan(2).Do(o => {o.Margin = new Thickness (0,45,0,0);}),
    element.Do(o
    => {o.Margin = new Thickness (0,5,0,5);}),
    }
    }
    }
    };
    dialog.OK
    += (s, args) => {
    //UI.Alert(((RichTextBox)rtb.RichTextBoxContent).Xaml.ToString());
    if (editor.GetRichEditor() != null)
    {
    UI.Alert(editor.GetRichEditor().Xaml.ToString());
    }
    };
    dialog.Show();

      

    3.  主要方法   

    为字体设置为斜体
    DependencyProperty property = TextElement.FontStyleProperty;
    var value
    = richEditor.Selection.GetPropertyValue(property);
    var newValue
    = FontStyles.Italic;
    if (value != DependencyProperty.UnsetValue && ((FontStyle)value) == FontStyles.Italic)
    {
    newValue
    = FontStyles.Normal;
    }
    richEditor.Selection.ApplyPropertyValue(property, newValue);

    在以上,首先取得选择的要设置字体的格式的文字,然后稍加判断是否需要设置格式,然后为其设置格式即可。

    在有些时候我们需要这样使用

    DependencyProperty property = Inline.TextDecorationsProperty;

    有些时候我们也可以直接使用Run,在RichTextBox生成的Xaml代码中我们就可以很清楚的看到。

    4.  相关问题(本人没搞明白)

       如何获取操作系统中现有的字体、大小然后遍历出来提供给用户?

       这里的图片不是url,不是url就不能保存了?

       恳切希望看到此问题的人不吝赐教,谢谢!

       

  • 相关阅读:
    沙尘天气,但还是要坚持锻炼
    为了欧冠,堕落两天
    NRF24L01测试板子完成了
    昨天参加ti的研讨会了
    自我安慰一下
    功率W与dBm的对照表及关系
    短时间提高英语口语方法
    看了一个星期的欧洲杯,熬阿
    最近比较忙,项目较累
    后台获取js赋给服务器控件的值
  • 原文地址:https://www.cnblogs.com/blackcore/p/1722167.html
Copyright © 2011-2022 走看看