有没有办法让GridSplitter不要将元素推出窗口? [英] Is there a way to have the GridSplitter not to push elements out of the window?
问题描述
使用下面的XAML时,我将GridSplitter向左拖动,将元素从窗口中移出。
如何保留窗框内的所有元素?
< Grid>
< Grid.ColumnDefinitions>
< ColumnDefinition Width =*/>
< ColumnDefinition Width =auto/>
< ColumnDefinition Width =auto/>
< /Grid.ColumnDefinitions>
< Button Grid.Column =0Content =0/>
< Button Grid.Column =1Content =1/>
< Button Grid.Column =2Content =2/>
< GridSplitter Grid.Column =1Width =5HorizontalAlignment =Left/>
< / Grid>
谢谢
我知道解决问题的唯一方法是将网格的左右两列的width属性设置为 Width =*
并给GridSplitter自己的列设置一个HorizontalAlignment设置为 HorizontalAlignment =Stretch
。您的代码最终会看起来像这样。
< Grid>
< Grid.ColumnDefinitions>
< ColumnDefinition Width =*/>
< ColumnDefinition Width =auto/>
< ColumnDefinition Width =*/>
< ColumnDefinition Width =auto/>
< /Grid.ColumnDefinitions>
< Button Grid.Column =0Content =0/>
< GridSplitter Grid.Column =1Width =5HorizontalAlignment =Stretch/>
< Button Grid.Column =2Content =1/>
< Button Grid.Column =3Content =2/>
< / Grid>
With the XAML below when I drag the GridSplitter to the left it pushes elements out of the window. How can I keep all elements within the window frame?
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="auto"/>
<ColumnDefinition Width="auto"/>
</Grid.ColumnDefinitions>
<Button Grid.Column="0" Content="0" />
<Button Grid.Column="1" Content="1" />
<Button Grid.Column="2" Content="2" />
<GridSplitter Grid.Column="1" Width="5" HorizontalAlignment="Left" />
</Grid>
Thanks
The only way I know to solve your problem is have the columns that are left and right of your gridsplitter have the width property set as Width="*"
and give the GridSplitter its own column with a HorizontalAlignment set as HorizontalAlignment="Stretch"
. Your code would then end up looking like this.
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="auto"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="auto"/>
</Grid.ColumnDefinitions>
<Button Grid.Column="0" Content="0" />
<GridSplitter Grid.Column="1" Width="5" HorizontalAlignment="Stretch"/>
<Button Grid.Column="2" Content="1" />
<Button Grid.Column="3" Content="2" />
</Grid>
这篇关于有没有办法让GridSplitter不要将元素推出窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!