Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get ProgressBar to fill StatusBarItem

I have a StatusBar that I'd like to house a TextBlock docked to the left and a ProgressBar filling the remaining width. In all my other experiences with the WPF ProgressBar, it will fill its given container, however in this situation it doesn't auto-size at all, it just appears as a tiny circle. Setting its height and width manually work fine, but I'd like it to scale to the remaining width of the StatusBar.

Here's my XAML for the StatusBar:

<StatusBar DockPanel.Dock="Bottom" Height="25">
    <StatusBarItem DockPanel.Dock="Left">
        <TextBlock x:Name="lblStatus"  Margin="5,0,0,0"/>
    </StatusBarItem>
    <StatusBarItem>
        <ProgressBar x:Name="pgbStatus" />
    </StatusBarItem>
</StatusBar>
like image 281
Mel Green Avatar asked Jan 15 '10 00:01

Mel Green


1 Answers

You just need one extra attribute: HorizontalContentAlignment="Stretch" on the StatusBarItem. Thus:

<StatusBar DockPanel.Dock="Bottom" Height="25">
  <StatusBarItem DockPanel.Dock="Left">
    <TextBlock x:Name="lblStatus" Margin="5,0,0,0"/>
  </StatusBarItem>
  <StatusBarItem HorizontalContentAlignment="Stretch">  <!-- Note extra attribute -->
    <ProgressBar x:Name="pgbStatus" />
  </StatusBarItem>
</StatusBar>
like image 166
itowlson Avatar answered Nov 07 '22 08:11

itowlson