1. 思想:
使用GridSplitter加到布局中,作为控件。
2. Xaml代码:
<Window
x:Class="TestWPF_Func1207.TestRichTextBox"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:VM="clr-namespace:TestWPF_Func1207.ViewModel"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:TestWPF_Func1207"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Title="TestRichTextBox"
Width="500"
Height="250"
d:DataContext="{d:DesignInstance Type=VM:TestRichTextBoxViewModel}"
Background="#F0F8FF"
mc:Ignorable="d">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="150" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="1*" />
</Grid.ColumnDefinitions>
<StackPanel Margin="10,10,10,10" Orientation="Vertical">
<Button
Width="Auto"
Margin="0,10,0,0"
Click="Button_Click"
Content="ShowExpression"
Style="{StaticResource BtnStyle_S}" />
</StackPanel>
<!--拖拽的分割线-->
<GridSplitter
Grid.Column="1"
Width="3"
HorizontalAlignment="Center"
Background="Orange"
ShowsPreview="True" />
<StackPanel Grid.Column="2" Grid.ColumnSpan="2">
<RichTextBox
x:Name="RichTxt"
Height="60"
Margin="10"
AcceptsReturn="True"
AutoWordSelection="True"
CaretBrush="OrangeRed"
InputMethod.IsInputMethodEnabled="False"
SpellCheck.IsEnabled="True"
VerticalScrollBarVisibility="Auto">
<FlowDocument>
<Paragraph x:Name="_paragraph" Margin="2" />
</FlowDocument>
</RichTextBox>
</StackPanel>
</Grid>
</Window>