WPF GridSplitter 分割窗口

WPF MicroUI无边框窗体使用 WindowChrome

<WindowChrome.WindowChrome>
   <WindowChrome CaptionHeight="50" UseAeroCaptionButtons="False"/>
</WindowChrome.WindowChrome>

 注:

  • CaptionHeight代表标题高度(也就是在哪个高度范围内可以拖动
  • UseAeroCaptionButtons表示是否禁用自带的最小最大化按钮(一般禁用,配合自定义按钮)

如果某个控件位于CaptionHeight设定的高度内,是不能被命中的,解决办法是在该控件内添加属性

WindowChrome.IsHitTestVisibleInChrome="True"

 如:

<Grid WindowChrome.IsHitTestVisibleInChrome="True"></Grid>

 拖动窗体

this.Loaded += (r, s) =>
{
    this.MouseDown += (x, y) =>
    {
        if (y.LeftButton == MouseButtonState.Pressed)
        {
            this.DragMove();
        }
    };
};

 

容器共享

<Grid Grid.IsSharedSizeScope="True">

 

网格大小可拖动 GridSplitter

示例:

<WindowChrome.WindowChrome>
    <WindowChrome CaptionHeight="0" UseAeroCaptionButtons="False" GlassFrameThickness="0"></WindowChrome>
</WindowChrome.WindowChrome>
<Grid>
    <Grid ShowGridLines="True">
        <Grid.RowDefinitions>
            <RowDefinition Height="80"/>
            <RowDefinition MinHeight="360"/>
            <RowDefinition Height="180" MinHeight="80"/>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition MinWidth="180" MaxWidth="640" Width="280"/>
            <ColumnDefinition MinWidth="280"/>
            <ColumnDefinition MinWidth="180" MaxWidth="640" Width="280"/>
        </Grid.ColumnDefinitions>
        <Border Background="AliceBlue" Grid.ColumnSpan="3"/>

        <Border Grid.Row="1" Background="Red"/>
        <GridSplitter Grid.Row="1" HorizontalAlignment="Right" Width="5" />

        <Border Background="Green" Grid.Row="1" Grid.Column="1">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition MinHeight="180"/>
                    <RowDefinition MinHeight="180" Height="80"/>
                </Grid.RowDefinitions>
                <Border Background="Gold"/>

                <Border Background="RosyBrown" Grid.Row="1"/>
                <GridSplitter Grid.Row="1" HorizontalAlignment="Stretch" VerticalAlignment="Top" Height="5" />
            </Grid>
        </Border>

        <Border Grid.Row="1" Grid.Column="2" Background="Bisque">
        </Border>
        <GridSplitter Grid.Row="1" Grid.Column="2" HorizontalAlignment="Left" Width="5" />


        <Border Grid.Row="2" Grid.ColumnSpan="3" Background="White"/>
        <GridSplitter Grid.Row="2" Grid.ColumnSpan="3" HorizontalAlignment="Stretch" VerticalAlignment="Top" Height="5" />
    </Grid>
</Grid>

 

 注意,因为是横向的所以设置的是高度(这个很重要!),水平方向布局需要进行拉伸(Stretch)

<GridSplitter Grid.Row="1" HorizontalAlignment="Stretch" VerticalAlignment="Bottom" Height="10" />

 

 

posted @ 2021-03-30 03:12  microsoft-zhcn  阅读(80)  评论(0编辑  收藏  举报