zoukankan      html  css  js  c++  java
  • 《RichTextBox》——— RichTextBox的使用

          在这篇文章中我将讨论WP7的RichTextBox控制(仍处在测试阶段)。在Silverlight 4中RichTextBox是一个众所周知的控制,所以Windows Phone 7.1(芒果)也一样可供RichTextBox。
          基本上RichTextBox代表一个富文本编辑控件,支持格式化的文本、超链接、内联图像和其他丰富的内容。
     
          当前Beta测试版RichTextBox有相当多的局限性
     * 没有默认的样式:没有默认的样式RichTextBox。使用RichTextBox控制你必须在你工程的App.xaml文件中添加一个新的风格,作为一个
        StaticResource。
     * 没有工具箱支持:RichTextBox的控制并不会出现在工具箱
     * 没有设计支持:RichTextBox的控制并不呈现在设计图面。为了解决这一问题,运行您的应用程序,并验证控制体现。
     * RichTextBox的控制是只读的
     
          还请注意,超链接和InlineUIContainer并非在任何情况下都能正确工作。因为一些原因,超链接可能将随机的抛出一个异常。InlineUIContainer不使用正确的UIElement内容也是如此。 最后,总结,看来唯一能正常在Windows Phone 7 Beta(芒果)工作的是paragraph对象,Span groups(Bold, Italic, and Underline)和Run对象。
     
          下面的基本任务可以在RichTextBox (WP7芒果)控制中工作:
    Task Implementation
    内容设置
    使用Paragraph来进行内容设置
    显示文本和行内 UIElement对象
    使用 InlineUIContainer元素
    显示超链接
    使用Hyperlink
    在只读模式显示内容 使用 IsReadOnly属性
     
     
     
     
     
    注意:只有当RichTextBox是只读属性时,用户界面元素才会被激活。
     
    要开始使用RichTextBox首先你必须添加一些默认的样式,你既可以在App.xaml中加,也可以作为一个StaticResource资源加在页面里。
    Option1、在App.xaml的资源中定义RichTextBox的默认样式:
     1 <Application.Resources> 
     2     <Style TargetType="RichTextBox"> 
     3         <Setter Property="FontSize" Value="{StaticResource PhoneFontSizeNormal}" /> 
     4         <Setter Property="Foreground" Value="{StaticResource PhoneForegroundBrush}" /> 
     5         <Setter Property="Background" Value="Transparent" /> 
     6         <Setter Property="BorderBrush" Value="Transparent" /> 
     7         <Setter Property="BorderThickness" Value="0"/> 
     8         <Setter Property="HorizontalContentAlignment" Value="Stretch" /> 
     9         <Setter Property="VerticalContentAlignment" Value="Center" /> 
    10         <Setter Property="Padding" Value="0" /> 
    11         <Setter Property="Template"> 
    12             <Setter.Value> 
    13                 <ControlTemplate TargetType="RichTextBox"> 
    14                     <Grid Background="Transparent"> 
    15                         <Border Background="{TemplateBinding Background}" 
    16                     BorderBrush="{TemplateBinding BorderBrush}"
    17                     BorderThickness="{TemplateBinding BorderThickness}"
    18                     Margin="{StaticResource PhoneHorizontalMargin}"> 
    19                             <ContentControl x:Name="ContentElement"
    20                         HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
    21                         VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
    22                         Padding="{TemplateBinding Padding}"/> 
    23                         </Border> 
    24                     </Grid> 
    25                 </ControlTemplate> 
    26             </Setter.Value> 
    27         </Setter> 
    28     </Style> 
    29 </Application.Resources>
    示例用法:为了展示RichTextBox的使用,我们在RichTextBox中添加一些内容,如:
    1 <RichTextBox Width="400" Height="200" Background="Transparent" BorderBrush="White" BorderThickness="5"> 
    2     <Paragraph> 
    3         <Run Text="A simple RichTextBox sample "/> 
    4         <Bold Foreground="Red">Some bold Text Here!</Bold> 
    5     </Paragraph> 
    6 </RichTextBox>
     
    Option2:在这种情况下,您可以在你的页面资源中定义RichTextBox的Style,加上一个“x:key”标识符,以便您可以使用StaticResource访问这个风格:
    1 <phone:PhoneApplicationPage.Resources> 
    2     <Style TargetType="RichTextBox" x:Key="rtbx"> 
    3         .//the same style as described in Option1 , the only difference is x:Key     
    4     </Style> 
    5 </phone:PhoneApplicationPage.Resources>
    示例用法:为了展示RichTextBox的使用,我们在RichTextBox中添加一些内容,如:
     
    1 <RichTextBox Width="400" Height="400" Background="Transparent" BorderBrush="White" BorderThickness="5" Style="{StaticResource rtbx}"> 
    2     <Paragraph> 
    3         <Run Text="A simple RichTextBox"/> 
    4         <Bold Foreground="Red">Some bold Text Here!</Bold> 
    5     </Paragraph> 
    6 </RichTextBox>

    运行如下:

     RichTextBox使用样例:
     这个示例展示如何使用Paragraph, Run, Bold, Italic  和 Underline对象
     
     1 <RichTextBox  Width="400" Height="300" > 
     2     <Paragraph> 
     3         <Run Text="A simple RichTextBox: "/> 
     4         <Italic Foreground="YellowGreen">Some Italic Text Here!</Italic> 
     5     </Paragraph> 
     6     <Paragraph> 
     7         <Underline Foreground="LightBlue">Some Underline Text Here!</Underline> 
     8     </Paragraph> 
     9     <Paragraph Foreground="Red"> 
    10         <Bold >Some Bold Text Here!</Bold> 
    11     </Paragraph> 
    12 </RichTextBox>

    运行结果:

    源码:

    MangoRichTextBoxDemo

  • 相关阅读:
    HBase Cassandra比较
    重新认识HBase,Cassandra列存储——本质是还是行存储,只是可以动态改变列(每行对应的数据字段)数量而已,当心不是parquet
    HBase底层存储原理——我靠,和cassandra本质上没有区别啊!都是kv 列存储,只是一个是p2p另一个是集中式而已!
    Cassandra 数据模型设计,根据你的查询来制定设计——反范式设计本质:空间换时间
    【LeetCode】【Python解决问题的方法】Best Time to Buy and Sell Stock II
    LVM逻辑卷管理命令
    Java引进和应用的包装类
    Android 4.0新组件:GridLayout详细说明
    【剑指offer】打印单列表从尾部到头部
    原因以及如何避免产生僵尸进程
  • 原文地址:https://www.cnblogs.com/qq278360339/p/2544810.html
Copyright © 2011-2022 走看看