问题
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