本文介绍了如何设置GridSplitter“窗格"的初始高度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在WPF窗口中使用了GridSplitter.拆分器上方是一个TreeView,下面是一个DockPanel,其中包含一个文本框.当我在TreeView中选择一个项目时,DockPanel的内容将通过数据绑定进行更新.

取决于TextBox的内容,Window的下部窗格会扩大和缩小大小.我希望它从高度X开始,并保持在该高度,除非GridSplitter被用户拖动.

我尝试在XAML中设置下部DockPanel的高度,但这可以固定DockPanel的高度,以便在移动GridSplitter时不调整其大小.也许解决方案涉及Grid.Row Heights?

这是我页面的一般结构.

Window
  Grid
    row1 Height="*":    TreeView
    row2 Height="5":    GridSplitter
    row3 Height="auto": DockPanel  // gets taller and shorter depending on its content.
      ...
      TextBox

顺便说一句:拖动GridSplitter后,调整大小停止,UI会按照我想要的方式运行.

解决方案

明确设置要具有初始大小的网格行的Height.

现在,在拖动GridSplitter时,第3行位于Auto上,并调整为内容大小,该值将被该行的当前高度替换.

I am using a GridSplitter in my WPF Window. Above the splitter is a TreeView, below is a DockPanel containing amongst other things a textbox. When I select an item in the TreeView, the DockPanel's contents are updated via data-binding.

Depending on the content of the TextBox, the lower pane of the Window expands and contracts in size. I want it to start at Height X, and stay at that Height unless the GridSplitter is dragged by the user.

I tried setting the Height of the lower DockPanel in the XAML, but this fixes the height of the DockPanel so that it doesn't resize when the GridSplitter is moved. Maybe the solution involves the Grid.Row Heights?

Here's the general structure of my page.

Window
  Grid
    row1 Height="*":    TreeView
    row2 Height="5":    GridSplitter
    row3 Height="auto": DockPanel  // gets taller and shorter depending on its content.
      ...
      TextBox

BTW: after I've dragged the GridSplitter, the resizing stops happening and the UI behaves how I want it to.

解决方案

Explicitly set the Height of the grid-row that you want to have an initial size.

Right now row3 is on Auto and resizes to content, as soon as you drag the GridSplitter that value is being replaced by the current height of the row.

这篇关于如何设置GridSplitter“窗格"的初始高度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-31 01:10