1、举例
<Window x:Class="WpfApplication1.com.view.TestWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:WpfApplication1.com.Data"
Title="测试窗口" Height="300" Width="500">
<Grid>
<RichTextBox Name="richTextBox" HorizontalAlignment="Left" Height="185" VerticalAlignment="Top" Width="386">
<FlowDocument>
<Paragraph>
This is a richTextBox. I can
<Bold>Bold</Bold> ,
<Italic>Italicize</Italic> ,
<Hyperlink>Hyperlink stuff</Hyperlink> right in my document.
</Paragraph>
</FlowDocument>
</RichTextBox>
<StackPanel HorizontalAlignment="Right" VerticalAlignment="Top">
<Button Content="按钮" Click="Button_Click"/>
</StackPanel>
</Grid>
</Window>
using System.Windows;
namespace WpfApplication1.com.view
{
/// <summary>
/// TestWindow.xaml 的交互逻辑
/// </summary>
public partial class TestWindow : Window
{
public TestWindow()
{
InitializeComponent();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
richTextBox.Document.Blocks.Clear();
}
}
}
RichTextBox 是一个有丰富内容的控件(包括文本、段落、超链接、可以设置粗体、斜体、内联图像 等等)
基本结构如下:
|