如何:创建 GridSplitter,用于自定义 DockPanel 的大小(C#、WPF)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23762169/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 11:45:28  来源:igfitidea点击:

How to: Create a GridSplitter, that customizes the size of a DockPanel (C#, WPF)

c#wpfdockpanel

提问by gpuk360

How to: Create a GridSplitter, that customizes the size of a DockPanel (C#, WPF)

如何:创建 GridSplitter,用于自定义 DockPanel 的大小(C#、WPF)

This is my GridSplittercode, but unfortunately it is not working: I am not allowed to change the size of my grid. I can see the GridSplitter, but I cannot use it.

这是我的GridSplitter代码,但不幸的是它不起作用:我不允许更改我的grid. 我可以看到GridSplitter,但我不能使用它。

<DockPanel DockPanel.Dock="Left" Name="dockPanel_1" Width="200">
    <StackPanel />
    <DockPanel />
</DockPanel>
<Grid>
    <GridSplitter ShowsPreview="True" Width="5" HorizontalAlignment="Right" VerticalAlignment="Stretch" />
</Grid>
<DockPanel DockPanel.Dock="Right" Name="dockPanel_2">
    <StackPanel />
    <DockPanel />
</DockPanel>

PS: If you know how to save the changed size, so that its to the same size when restarting the application, just add to your post.

PS:如果您知道如何保存更改的大小,以便在重新启动应用程序时其大小相同,只需添加到您的帖子中即可。

Thanks in advance.

提前致谢。

回答by dkozl

If you want to be able to resize columns/row then instead of DockPanelyou can use Gridwith GridSplitter

如果您希望能够调整列/行的大小,那么DockPanel您可以使用GridwithGridSplitter

<Grid>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="200"/>
        <ColumnDefinition/>
    </Grid.ColumnDefinitions>
    <DockPanel Name="dockPanel_1">
        <StackPanel />
        <DockPanel />
    </DockPanel>
    <GridSplitter Width="5" HorizontalAlignment="Right" VerticalAlignment="Stretch" ResizeBehavior="CurrentAndNext"/>
    <DockPanel Grid.Column="1" Name="dockPanel_2">
        <StackPanel />
        <DockPanel />
    </DockPanel>
</Grid>