WPF实现科拖拽分隔栏

WPF中有DockPanel,但是这个DockPanel如果之间有一个分隔栏,但是,是不能拖动分隔栏来进行调整分隔栏两边的控件的大小。虽然DockPanel不具备这样的功能,我们只能使用Grid和GridSplitter来实现这个需求。

实现代码如下:

<Window x:Class="GridSplitterWpfApplication1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="25"/>
            <RowDefinition/>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="150"/>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition/>
        </Grid.ColumnDefinitions>
        <TextBox Grid.ColumnSpan="3" BorderBrush="Black"/>
        <TextBox Grid.Row="1" BorderBrush="Black"/>
        <GridSplitter Grid.Row="1" Grid.Column="1"
                      VerticalAlignment="Stretch"
                      HorizontalAlignment="Center"
                      Width="1"
                      Background="Gray"
                      ShowsPreview="True"/>
        <TextBox Grid.Row="1" Grid.Column="2" BorderBrush="Black"/>
    </Grid>
</Window>
动手试一试!

你可能感兴趣的:(Class,WPF,textbox)