In my WPF Window, I've got a Status Bar and a TextBox. Now what I want to achieve is in my code, I have a button which collapses and shows the Status Bar. When I click on the button, the Status Bar collapses therefore the control will be collapsed
and no longer shown and so the Textbox will fill the space of the Status Bar. When the button is pressed again, the Status bar will be visible
and will push the Textbox up.
I've tried only this but it didn't work. THe problem is that the Status Bar would hide but the textbox would still be in the same place and not take up the space. Someone please help me that would be greatly appreciated.
<StackPanel>
<Grid>
<StatusBar Height="30" VerticalAlignment="Bottom">
<StatusBarItem Content="Last Saved Not Saved"/>
<StatusBarItem HorizontalAlignment="Right">
<StackPanel Orientation="Horizontal">
<StatusBarItem Content="Character 0 Word 0"/>
<StatusBarItem Content="Ln 1, Ch 0"/>
</StackPanel>
</StatusBarItem>
</StatusBar>
<TextBox x:Name="textBox" Height="380" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Top" Margin="0,24,0,0"/>
</Grid>
</StackPanel>
As we spoke before, to achieve functionality of the TextBox
stretching, you "could" use DockPanel
, like so:
<DockPanel MinHeight="380" LastChildFill="True">
<StatusBar DockPanel.Dock="Top" Height="30"/>
<TextBox DockPanel.Dock="Bottom"/>
</DockPanel>
There are also other ways i.e. using Grid.RowsDefinitions
but for the sake of this conversation let's stick to the DockPanel
.
Happy coding.