Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF ProgressBar in StatusBar won't stretch

New to WPF & I have the following XAML

<Window x:Class="Wpf.RossKiosk.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Topmost="True" WindowStartupLocation="CenterScreen" WindowState="Maximized" ResizeMode="NoResize" WindowStyle="None">
<DockPanel LastChildFill="True">

    <StatusBar Name="StatusBarMain" Height="30"  DockPanel.Dock="Bottom">
        <StatusBarItem HorizontalContentAlignment="Left">
            <TextBlock x:Name="TextBlockStatus" Margin="5,0,0,0" />
        </StatusBarItem>
        <StatusBarItem HorizontalContentAlignment="Stretch">
            <ProgressBar x:Name="ProgressBarMain" IsIndeterminate="True" Height="15" />
        </StatusBarItem>
        <StatusBarItem HorizontalContentAlignment="Right">
            <TextBlock x:Name="TextBlockInfo" Margin="5,0,0,0" TextAlignment="Right" />
        </StatusBarItem>
    </StatusBar>

    <Grid Name="GridMain">

        <!-- Dynamically Created buttons -->


    </Grid>


</DockPanel>

I want the ProgressBar to fill the centre portion of the StatusBar but it only shows itself a few pixels in width. Any ideas?

like image 272
RedEyedMonster Avatar asked Dec 08 '22 16:12

RedEyedMonster


2 Answers

This is due to StatusBar using a DockPanel to lay out its children by default. Please see my question and answer here.

like image 76
Kent Boogaart Avatar answered Dec 11 '22 07:12

Kent Boogaart


You will need to use a Grid. A DockPanel or StackPanel will not suffice for you. Try:

    <Grid>
    <StatusBar Name="StatusBarMain" Height="30" HorizontalAlignment="Stretch">
    <StatusBarItem HorizontalContentAlignment="Left">
        <TextBlock x:Name="TextBlockStatus" Margin="5,0,0,0" />
    </StatusBarItem>
    <StatusBarItem HorizontalContentAlignment="Stretch">
        <ProgressBar x:Name="ProgressBarMain" IsIndeterminate="True" Height="15" />
    </StatusBarItem>
    <StatusBarItem HorizontalContentAlignment="Right">
        <TextBlock x:Name="TextBlockInfo" Margin="5,0,0,0" TextAlignment="Right" />
    </StatusBarItem>
   </StatusBar>
    </Grid>
like image 26
Jeff Avatar answered Dec 11 '22 08:12

Jeff