I've got a fairly minimal window defined in XAML. The StatusBar unfortunately takes only half the width, and doesn't stretch to the whole width of the window.
Why is that / how do I fix it?
<Window x:Class="TheProject.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:TheProject"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="771.382">
<DockPanel Margin="0,0,0,0" LastChildFill="False">
<Button Content="Button" HorizontalAlignment="Left" Margin="289,127,0,0" VerticalAlignment="Top" Width="75" Click="Button_Click"/>
<StatusBar DockPanel.Dock="Bottom" Height="21">
<StatusBarItem x:Name="actionStatus" Content="StatusBarItem"/>
</StatusBar>
</DockPanel>
</Window>
The default value of the DockPanel.Dock property is Left. That is why your Button (which comes first in the markup) is aligned left and then the remaining space to the right is used to align the other controls. Since you assign Bottom to the StatusBar (which comes second), it will be aligned at the bottom of the remaining space. Order of controls matters in a DockPanel.
You can test this by switching the order of the controls, which will align the StatusBar first.
<DockPanel Margin="0,0,0,0" LastChildFill="False">
<StatusBar DockPanel.Dock="Bottom" Height="21">
<StatusBarItem x:Name="actionStatus" Content="StatusBarItem"/>
</StatusBar>
<Button Content="Button" HorizontalAlignment="Left" Margin="289,127,0,0" VerticalAlignment="Top" Width="75" Click="Button_Click"/>
</DockPanel>
Another approach is to set the the Dock property on the Button to Top, which aligns it at the top and leaves the remaining space below it, which will align the StatusBar right, too.
<DockPanel Margin="0,0,0,0" LastChildFill="False">
<Button DockPanel.Dock="Top" Content="Button" HorizontalAlignment="Left" Margin="289,127,0,0" VerticalAlignment="Top" Width="75" Click="Button_Click"/>
<StatusBar DockPanel.Dock="Bottom" Height="21">
<StatusBarItem x:Name="actionStatus" Content="StatusBarItem"/>
</StatusBar>
</DockPanel>
Just as a note, there are certainly other options, too, like removing LastChildFill="False" and defining the button last, but that really depends on your requirements. The important bit to understand is how DockPanel divides space and in what order, see this for reference:
The position of child elements of a
DockPanelon the screen is determined by theDockproperty of the respective child elements and the relative order of those child elements under theDockPanel. Therefore, a set of child elements with the sameDockproperty values can be positioned differently on the screen depending on the order of these children under theDockPanel. Child ordering effects positioning because theDockPaneliterates through its child elements in order, setting the position of each element depending on remaining space.