Search code examples
c#wpfstatusbardockpanel

WPF StatusBar without content isn't visible inside of Dock Panel


I am learning WPF from this book: WPF in Action with Visual Studio 2008 There is some layouting example using DockPanel with Menu, ToolBarTry, StatusBar and Grid inside.

I've coded this UI layout by the book:

    <Window x:Class="WpfSandBox.WikiManager"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Wiki Manager" Height="300" Width="300">
    <Grid>

    <DockPanel LastChildFill="True">

        <Menu DockPanel.Dock="Top">
            <MenuItem x:Name="File" Header="_File"/>
            <MenuItem x:Name="Edit" Header="_Edit"/>
            <MenuItem x:Name="Format" Header="_Format"/>
            <MenuItem x:Name="Tools" Header="_Tools"/>
            <MenuItem x:Name="Help" Header="_Help"/>
        </Menu>

        <ToolBarTray DockPanel.Dock="Top">
            <ToolBar>
                <Button>New</Button>
                <Button>Print</Button>
                <Button>Spell</Button>
                <Button>Check</Button>
                <Button>Options</Button>
            </ToolBar>
        </ToolBarTray>

        <StatusBar DockPanel.Dock="Bottom"></StatusBar>

        <Grid></Grid>

    </DockPanel>

</Grid>

The problem is, that StatusBar is hidden, as it doesn't have any content yet, while in book it's visible on the bottom of DockPanel. Maybe the forgot to mention some parameter to be set (this piece of XAML is missing in the book because they are making this layout only in designer).


Solution

  • Try setting some content(event an empty textblock) to the StatusBar to give it size:

        <StatusBar DockPanel.Dock="Bottom" Name="StatusBar_Control">
            <StatusBarItem>
                <TextBlock Name="StatusBar_TextBlock" Text=""/>
            </StatusBarItem>
        </StatusBar>