ProfK
ProfK

Reputation: 51063

Emulating Dock and Anchor in a WPF window

I have a very simple terminal application that sens and receives characters from a serial port. This currently uses two fixed size TextBox controls, one beneath the other. I now would like to split the main window into two halves that keep their 50% size, with a TextBlock for a label and TextBox for characters in each half.

I suspect I could use the simple StackPanel for this, but how do I specify, in the inner stackpanels, that the label panel has a fixed height, and the text must fill the remaining height. How do I specify that the outer two panels each always occupy 50% of the height?

Upvotes: 2

Views: 667

Answers (2)

jjrdk
jjrdk

Reputation: 1892

Why don't you do:

<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<StackPanel Orientation="Vertical">
<TextBlock Text="Title1"/><!-- You could use a Label control here instead-->
<TextBox />
</StackPanel>
<StackPanel Grid.Row="1" Orientation="Vertical">
<TextBlock Text="Title1"/><!-- You could use a Label control here instead-->
<TextBox />
</StackPanel>
</Grid>

Upvotes: 1

Henk Holterman
Henk Holterman

Reputation: 273179

For the outer panels, use a Grid.

The InnerPanels can be done as a DockPanel (with LastChildFill=true)

Upvotes: 0

Related Questions