How to set initial height of a GridSplitter 'pane'?

耗尽温柔 提交于 2020-01-02 02:32:08

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/5662978/how-to-set-initial-height-of-a-gridsplitter-pane

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!