频道栏目
首页 > 资讯 > Windows Phone > 正文

windows phone7.1中两个新增控件

11-06-01        来源:[db:作者]  
收藏   我要投稿

RichTextBox
在wp7中,所有的控件都无法实现图文混排,这个控件解决了无法图文混排的问题,使微博和聊天软件不在只是文字显示那么单调了。但是这个控件目前还并不完善,只能够显示而无法进行输入,另外使用起来也比较麻烦。以下就是这个控件的使用方法:

1.       XAML中直接添加

这个控件无法显示在ToolBox列表中,需要通过手工方式来自已添加。


<RichTextBox Width="400" Height="400" Background="White" IsReadOnly="True" FontSize="30" VerticalContentAlignment="Top">

                <Paragraph>

                    <Run Foreground="Red" FontStyle="Italic" Text="Red Text"/>

                </Paragraph>

                <Paragraph Foreground="Blue">

                    <Run Text="Blue Text "/>

                    <Bold>This is bold</Bold>

                </Paragraph>

                <Paragraph Foreground="Black">

                    <Run Text="Black Text "/>

                    <Hyperlink>Click Here</Hyperlink>

                    <Bold>test Bold Text</Bold>

                </Paragraph>

                <Paragraph>

                    A RichTextBox with<Bold>initial content</Bold> in it.

                </Paragraph>

       

            </RichTextBox>
 

这样就实现了图文混排,以及多种文字效果的同时显示。

2.       代码实现


RichTextBox rtb = new RichTextBox();

            rtb.Width = 400;

            rtb.Height = 400;

            rtb.FontSize = 30;

            rtb.Background = new SolidColorBrush(Colors.White);

            rtb.VerticalContentAlignment = System.Windows.VerticalAlignment.Top;

 

            Paragraph parag = new Paragraph();

            Run run = new Run();

            run.Foreground = new SolidColorBrush(Colors.Red);

            run.Text = "Red Text";

            parag.Inlines.Add(run);

            rtb.Blocks.Add(parag);

 

            parag = new Paragraph();

            parag.Foreground = new SolidColorBrush(Colors.Blue);

            run = new Run();

            run.Text = "Blue Text";

            parag.Inlines.Add(run);

 

 

            Bold bold = new Bold();

            bold.Inlines.Add("This is bold Text");

            parag.Inlines.Add(bold);

 

            rtb.Blocks.Add(parag);

 

            parag = new Paragraph();

            parag.Foreground = new SolidColorBrush(Colors.Black);

            run = new Run();

            run.Text = "Black Text";

            parag.Inlines.Add(run);

 

            Hyperlink hl = new Hyperlink();

            hl.Inlines.Add("Click Here");

            parag.Inlines.Add(hl);

 

            bold = new Bold();

            bold.Inlines.Add("test Bold Text");

            parag.Inlines.Add(bold);

            run = new Run();

            run.Text = "A RichTextBox with";

            parag.Inlines.Add(run);

            bold = new Bold();

            bold.Inlines.Add("initial content");

            parag.Inlines.Add(bold);

            run = new Run();

            run.Text = "in it.";

            parag.Inlines.Add(run);

 

            rtb.Blocks.Add(parag);

 

            ContentPanel.Children.Add(rtb);
 

这两种方法实现的是同一个效果。


3.       注意事项

l 这个控件在加入到工程之前,需要在APP.xaml文件的Resource节中添加如下xaml,否则无法显示。


<Application.Resources>

        <Style TargetType="RichTextBox">

            <Setter Property="FontSize" Value="{StaticResource PhoneFontSizeNormal}" />

   &

相关TAG标签
上一篇:安全随笔1:谨慎一次MD5值的可被穷举性
下一篇:基于.NET的分词软件设计与实现V1.0--总体思路及算法实现
相关文章
图文推荐

关于我们 | 联系我们 | 广告服务 | 投资合作 | 版权申明 | 在线帮助 | 网站地图 | 作品发布 | Vip技术培训 | 举报中心

版权所有: 红黑联盟--致力于做实用的IT技术学习网站