Reputation: 1401
I'm new to WPF and I'm trying to create a Window with two text boxes, the RichTextBox at the top, which uses most of the available space, and a TextBox at the bottom. My issue is the TextBox at the bottom is not showing. I have it at the bottom of the DockPanel. What am I missing?
Where is the XAML:
<Window x:Class="WpfApp1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApp1"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="750" MinHeight="400" MinWidth="600" Background="Black">
<DockPanel
Margin="5"
Height="Auto"
Width="Auto">
<RichTextBox
Name="richTB"
IsEnabled="True"
VerticalScrollBarVisibility="Visible"
IsReadOnly="True">
<FlowDocument
Name="flowDoc"
PagePadding="0">
<Paragraph>
<Run Text="Test" Foreground="Red"></Run>
<Run Text="Foo" Foreground="Blue"></Run>
</Paragraph>
</FlowDocument>
</RichTextBox>
<TextBox
Name="textBox"
KeyDown="EnterPressed"
Background="Plum"
DockPanel.Dock="Bottom">
</TextBox>
</DockPanel>
</Window>
Upvotes: 0
Views: 522
Reputation: 652
You textbox has no content. The dockpanel sizes its components to the needed size, but because it has no content it has no visible size.
Place some text in it and it will show.
Upvotes: 0
Reputation: 2343
You may have to reorder the children of the DockPanel. The last child fill uses the Last child in the list of children, it isn't based on where the children are laid out within the DockPanel.
<Window x:Class="WpfApp1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApp1"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="750" MinHeight="400" MinWidth="600" Background="Black">
<DockPanel
Margin="5"
Height="Auto"
Width="Auto">
<TextBox
Name="textBox"
KeyDown="EnterPressed"
Background="Plum"
DockPanel.Dock="Bottom">
</TextBox>
<RichTextBox
Name="richTB"
IsEnabled="True"
VerticalScrollBarVisibility="Visible"
IsReadOnly="True">
<FlowDocument
Name="flowDoc"
PagePadding="0">
<Paragraph>
<Run Text="Test" Foreground="Red"></Run>
<Run Text="Foo" Foreground="Blue"></Run>
</Paragraph>
</FlowDocument>
</RichTextBox>
</DockPanel>
</Window>
Upvotes: 2