gpt4 book ai didi

.net - 如何防止WPF GridSplitter更改网格的大小?

转载 作者:行者123 更新时间:2023-12-04 13:25:16 24 4
gpt4 key购买 nike

WPF GridSplitter使我的网格比我的窗口更宽!

我有一个带有GridSplitter的WPF网格。如果我调整列的大小,则可以使网格比窗口宽且不可见。

它是这样开始的:

WPF Grid http://img201.imageshack.us/img201/9505/onehg6.jpg

但是在加宽左列之后,我再也看不到右列(绿色):

WPF GridSplitter http://img201.imageshack.us/img201/1804/twomy6.jpg

我究竟做错了什么?如何防止GridSplitter更改网格的大小?

更新:

我还在为此苦苦挣扎。我现在尝试在网格内嵌套网格。那没有帮助。这是我的XAML ColumnDefinitions,RowDefinitions和GridSplitters ...

<Window ... >
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" MinWidth="150" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" MinWidth="400" />
</Grid.ColumnDefinitions>
<GridSplitter
ResizeDirection="Columns"
ResizeBehavior="BasedOnAlignment"
Grid.Column="1"
HorizontalAlignment="Center"
VerticalAlignment="Stretch"
Width="2"
Margin="0,5,0,5"
Panel.ZIndex="1"/>
<Grid Grid.Column="0">
...
</Grid>
<Grid Grid.Column="2">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" MinWidth="150" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" MinWidth="200" />
</Grid.ColumnDefinitions>
<GridSplitter
ResizeDirection="Columns"
ResizeBehavior="PreviousAndNext"
Grid.Column="1"
HorizontalAlignment="Center"
VerticalAlignment="Stretch"
Width="2"
Margin="0,5,0,5"
Panel.ZIndex="1"/>
<Grid Grid.Column="0">
...
</Grid>
<Grid Grid.Column="2">
...
</Grid>
</Grid>
</Grid>
</Window>

更新:

我认为问题出在WebBrowser控件上。看到新问题:

WPF GridSplitter Doesn't Work With WebBrowser Control?

最佳答案

如果调整了窗口的大小,使其宽度小于列的MinWidths的总和,则会看到列被切除,但是否则我无法重现您的问题:

<Window 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">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition MinWidth="150" Width="*"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition MinWidth="400" Width="*"/>
</Grid.ColumnDefinitions>
<GridSplitter
Width="2"
Grid.Column="1"
HorizontalAlignment="Center"
Margin="0,5,0,5"
Panel.ZIndex="1"
VerticalAlignment="Stretch"
ResizeBehavior="BasedOnAlignment"
ResizeDirection="Columns"/>
<Grid Grid.Column="0">
<Border Background="Red" Margin="5"/>
</Grid>
<Grid Grid.Column="2">
<Grid.ColumnDefinitions>
<ColumnDefinition MinWidth="150" Width="*"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition MinWidth="200" Width="*"/>
</Grid.ColumnDefinitions>
<GridSplitter
Width="2"
Grid.Column="1"
HorizontalAlignment="Center"
Margin="0,5,0,5"
Panel.ZIndex="1"
VerticalAlignment="Stretch"
ResizeBehavior="PreviousAndNext"
ResizeDirection="Columns"/>
<Grid Grid.Column="0">
<Border Background="Green" Margin="5"/>
</Grid>
<Grid Grid.Column="2">
<Border Background="Blue" Margin="5"/>
</Grid>
</Grid>
</Grid>
</Window>

展开红色列,它只会扩展到右边的列达到其MinWidth 400为止,它不会从页面启动。

您可能正在设置Window或最外面的Grid的其他属性,这将导致此行为...

关于.net - 如何防止WPF GridSplitter更改网格的大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/279557/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com