4

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?

Nigel B
  • 3,577
  • 3
  • 34
  • 52
  • try to wrap all your statusbaritems into a grid and see if it works. – David Apr 23 '13 at 15:29
  • This helped me, but I needed to add Grid Row and Column Definitions to make it work properly.

    
    <Grid VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Height="Auto" ToolTip="abc213">
                  <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"></RowDefinition>
                    <RowDefinition Height="*"></RowDefinition>
                </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*"></ColumnDefinition>
    
    – Scott Shaw-Smith Jan 27 '15 at 16:37
  • I am having trouble formatting my answer. please disregard – Scott Shaw-Smith Jan 27 '15 at 16:45
  • answer is here: http://stackoverflow.com/questions/2068601/get-progressbar-to-fill-statusbaritem – CAD bloke May 11 '16 at 09:09

4 Answers4

9

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

Community
  • 1
  • 1
Kent Boogaart
  • 175,602
  • 35
  • 392
  • 393
7

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>
Jeff
  • 972
  • 5
  • 11
0

This helped me, but I needed to add Grid Row and Column Definitions to make it work properly.

<Grid VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Height="Auto" ToolTip="abc213">
          <Grid.RowDefinitions>
            <RowDefinition Height="Auto"></RowDefinition>
            <RowDefinition Height="*"></RowDefinition>
        </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*"></ColumnDefinition>
-2

This stretches the progress bar to its container

<StatusBarItem  Name="progressBarContainer">
    <ProgressBar Height="{Binding ElementName=progressBarContainer, Path=ActualHeight}" Width="{Binding ElementName=progressBarContainer, Path=ActualWidth}" Value="50" />
</StatusBarItem>
fab
  • 2,479
  • 1
  • 16
  • 6