WPF中添加布局拖拽功能 (添加GridSplitter)

14 篇文章 0 订阅

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>

3. 效果:

  • 4
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值