简体   繁体   English

如果用户在控制加载之前更改 gridsplitter 的位置,则如何在 wpf c# 中将列/行附加到 GridSplitter

[英]How to change position of gridsplitter if user change it before control loading inside column/row attach to GridSplitter in wpf c#

 <Grid Grid.Row="1" Visibility="Collapsed" Name="Main_Grid" > <Grid.ColumnDefinitions> <ColumnDefinition Width="Auto" MinWidth="100" MaxWidth="1000"/> <ColumnDefinition Width="2" /> <ColumnDefinition Width="*"/> </Grid.ColumnDefinitions> <Grid Grid.Column="0"> <UserControl/> </Grid> <GridSplitter Grid.Column="1" VerticalAlignment="Stretch" HorizontalAlignment="Left" Margin="0" ResizeDirection="Columns" ShowsPreview="False"> <Grid Grid.Column="2"> </Grid>

Here is my Grid Structure .这是我的网格结构。

After loading application I set Visibility of UserControl Visible/Collapsed depends on DataContext.加载应用程序后,我设置了 UserControl Visible/Collapsed 的 Visibility 取决于 DataContext。

First time FirstColumn take width as per need(as Width property of ColumnDefination is define as "Auto").第一次 FirstColumn 根据需要采用宽度(因为 ColumnDefination 的 Width 属性定义为“自动”)。

But if user move GridSplitter and after that if I assign new Datacontext to User control or click something in UserControl which has different with GridSplitter remain at old position where user left.但是,如果用户移动 GridSplitter 之后,如果我将新的 Datacontext 分配给用户控件或单击 UserControl 中与 GridSplitter 不同的内容,则会保留在用户离开的旧位置。

How to refresh it so that it First GridColumn Take Width as per need and GridSplitter should appear attach to it.如何刷新它以便它首先根据需要使用 GridColumn 宽度,并且 GridSplitter 应该显示为附加到它。

So I understand that once the user had changed the position of GridSplitter manually, it will no longer automatically adjust its position even after the size of adjacent Grid changed.所以我理解一旦用户手动更改了GridSplitter的位置,即使相邻Grid的大小发生变化,它也不会再自动调整其位置。 In such case, you can revive Auto settings of ColumnDefinition by setting it again from code behind.在这种情况下,您可以通过从后面的代码中再次设置来恢复 ColumnDefinition 的Auto设置。

this.Main_Grid.ColumnDefinitions[0].Width = GridLength.Auto;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM