GridSplitter 无法调整内容大小的问题

发布于 2024-09-07 10:35:50 字数 1947 浏览 2 评论 0原文

首先,我是 XAML 新手,所以如果我做了一些愚蠢的事情,请原谅我。

我已将页面精简为以下示例 XAML(可在 XamlPad 中查看):

<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
xmlns:sys="clr-namespace:System;assembly=mscorlib" 
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480">
    <Grid ShowGridLines="True">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="200" MinWidth="150"  />
            <ColumnDefinition />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="3*" />
            <!--<RowDefinition Height="Auto" />-->
            <RowDefinition MaxHeight="25" Height="25" MinHeight="25" />
            <RowDefinition Height="1*"/>
        </Grid.RowDefinitions>
        <Grid Grid.RowSpan="4" Grid.Row="0" Grid.Column="0" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" />
        <GridSplitter Grid.Row="0" Grid.RowSpan="4" Width="4" />
        <Frame >
        </Frame>
        <GridSplitter Grid.Row="0" Height="4" Grid.Column="1" HorizontalAlignment="Stretch" VerticalAlignment="Bottom" />
        <Grid Grid.Column="2" Grid.Row="2" VerticalAlignment="Stretch" HorizontalAlignment="Stretch"/>
        <ScrollViewer VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto" Grid.Column="2" Grid.Row="3">
            <Grid VerticalAlignment="Stretch" HorizontalAlignment="Stretch" />
        </ScrollViewer>
    </Grid>
</Page>

我想要发生的是让水平网格拆分器调整顶部面板的大小,移动底部网格(我希望将其保持在 25 高度)和 Scrollviewer控制下来。

我尝试将水平网格拆分器放入它自己的行中,这会将内容向下移动,但会缩小顶部网格的内容,这不是我想要的。

关于我做错了什么有什么建议吗?跟身高比例有关系吗?

First off I'm new to XAML so forgive me if I've done something stupid.

I have stripped down my page to the following example XAML (viewable in XamlPad):

<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
xmlns:sys="clr-namespace:System;assembly=mscorlib" 
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480">
    <Grid ShowGridLines="True">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="200" MinWidth="150"  />
            <ColumnDefinition />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="3*" />
            <!--<RowDefinition Height="Auto" />-->
            <RowDefinition MaxHeight="25" Height="25" MinHeight="25" />
            <RowDefinition Height="1*"/>
        </Grid.RowDefinitions>
        <Grid Grid.RowSpan="4" Grid.Row="0" Grid.Column="0" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" />
        <GridSplitter Grid.Row="0" Grid.RowSpan="4" Width="4" />
        <Frame >
        </Frame>
        <GridSplitter Grid.Row="0" Height="4" Grid.Column="1" HorizontalAlignment="Stretch" VerticalAlignment="Bottom" />
        <Grid Grid.Column="2" Grid.Row="2" VerticalAlignment="Stretch" HorizontalAlignment="Stretch"/>
        <ScrollViewer VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto" Grid.Column="2" Grid.Row="3">
            <Grid VerticalAlignment="Stretch" HorizontalAlignment="Stretch" />
        </ScrollViewer>
    </Grid>
</Page>

What I want to happen is for the Horizontal Grid Splitter to resize the top panel, moving the bottom Grid (which I want to keep at 25 height) and Scrollviewer controls down.

I've tried putting the Horizontal grid splitter into it's own Row and this moves the content down but it shrinks the content of the top grid which is not what I'm looking for.

Any suggestions as to waht I'm doing wrong? Is it something to do with the proportional height?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

眼泪淡了忧伤 2024-09-14 10:35:50

首先,您定义了拆分器,就好像它们适用于多个行和列,但它们实际上必须有自己的行或列,并且它们适用于相邻的行/列,因此您之前处于正确的轨道上。

问题是比例(星号)行。为了使分割器工作,至少相邻行/列之一必须是固定(像素)大小的,或者它不能用鼠标调整,而是通过一些奇怪的比例移动来调整。

我不明白你的“但它缩小了顶部网格的内容,这不是我想要的”评论,所以它可能需要更多的解释,我已经做了一些猜测,但是下面显示的 XAML 文件具有其自身行为的拆分器:

 <Grid ShowGridLines="True">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="191.5"  />
            <ColumnDefinition Width="8.5"/>
            <ColumnDefinition />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="194" />
            <RowDefinition Height="0.148*"/>
            <RowDefinition MaxHeight="25" Height="25" MinHeight="25" />
            <RowDefinition Height="0.852*"/>
        </Grid.RowDefinitions>
        <Grid Grid.RowSpan="4" Grid.Row="0" Grid.Column="0" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Grid.ColumnSpan="2" Margin="0,0,-0.5,0" />
        <sdk:GridSplitter Grid.Row="0" Grid.RowSpan="4" Grid.Column="1" HorizontalAlignment="Stretch" Margin="0.5,0,-0.5,0" />
        <Frame >
        </Frame>
        <sdk:GridSplitter Grid.Row="1" HorizontalAlignment="Stretch" Grid.ColumnSpan="3" />
        <Grid Grid.Column="2" Grid.Row="3" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Margin="0.5,0,-1,0"/>
        <ScrollViewer VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto" Grid.Column="2" Grid.Row="3" Margin="0.5,0,-1,0">
            <Grid VerticalAlignment="Stretch" HorizontalAlignment="Stretch" />
        </ScrollViewer>
    </Grid>

Firstly you have defined the splitter as if they apply to multiple rows and columns, but they actually have to have a row or column of their own and they apply to the adjacent rows/columns, so you were on the right track before.

The problem is the proportional (star) rows. For a splitter to work at least one of the adjacent rows/columns has to be fixed (pixel) sized or it does not adjust with the mouse but by some weird proportional movement instead.

I did not understand your "but it shrinks the content of the top grid which is not what I'm looking for" comment, so it might need some more explaining and I have made some guesses, but the XAML file shown below has the splitter behaving themselves:

 <Grid ShowGridLines="True">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="191.5"  />
            <ColumnDefinition Width="8.5"/>
            <ColumnDefinition />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="194" />
            <RowDefinition Height="0.148*"/>
            <RowDefinition MaxHeight="25" Height="25" MinHeight="25" />
            <RowDefinition Height="0.852*"/>
        </Grid.RowDefinitions>
        <Grid Grid.RowSpan="4" Grid.Row="0" Grid.Column="0" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Grid.ColumnSpan="2" Margin="0,0,-0.5,0" />
        <sdk:GridSplitter Grid.Row="0" Grid.RowSpan="4" Grid.Column="1" HorizontalAlignment="Stretch" Margin="0.5,0,-0.5,0" />
        <Frame >
        </Frame>
        <sdk:GridSplitter Grid.Row="1" HorizontalAlignment="Stretch" Grid.ColumnSpan="3" />
        <Grid Grid.Column="2" Grid.Row="3" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Margin="0.5,0,-1,0"/>
        <ScrollViewer VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto" Grid.Column="2" Grid.Row="3" Margin="0.5,0,-1,0">
            <Grid VerticalAlignment="Stretch" HorizontalAlignment="Stretch" />
        </ScrollViewer>
    </Grid>
岁月静好 2024-09-14 10:35:50

如果我正确理解你的问题。
您应该能够从内部网格中取出 VerticalAlignment="Stretch" 和 Horizo​​ntalAlignment="Stretch" 并获得您想要的内容。

gridsplitter 不喜欢不同行(或列)中的其他内容将两个对齐设置为拉伸。

If I understand your problem correctly.
You should be able to take out the VerticalAlignment="Stretch" and HorizontalAlignment="Stretch" from your inner grid and get what you want.

The gridsplitter doesn't like other content in a different row (or col) that has both Allignments set to stretch.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文