开发者

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开发者_如何学C" Height="25">
    <StatusBarItem DockPanel.Dock="Left">
        <TextBlock x:Name="lblStatus"  Margin="5,0,0,0"/>
    </StatusBarItem>
    <StatusBarItem>
        <ProgressBar x:Name="pgbStatus" />
    </StatusBarItem>
</StatusBar>


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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜