Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

392
Vistas
Why is the StatusBar half the width of the window?

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>
over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

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 DockPanel on the screen is determined by the Dock property of the respective child elements and the relative order of those child elements under the DockPanel. Therefore, a set of child elements with the same Dock property values can be positioned differently on the screen depending on the order of these children under the DockPanel. Child ordering effects positioning because the DockPanel iterates through its child elements in order, setting the position of each element depending on remaining space.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda