4

WPF 新手,我有以下 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>

我希望 ProgressBar 填充 StatusBar 的中心部分,但它只显示几个像素的宽度。有任何想法吗?

4

4 回答 4

9

这是由于默认情况下StatusBar使用 aDockPanel来布置其子级。请在此处查看我的问题和答案。

于 2013-04-23T15:43:43.863 回答
7

您将需要使用网格。DockPanel 或 StackPanel 不足以满足您的需求。尝试:

    <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>
于 2013-04-23T15:42:45.190 回答
0

这对我有帮助,但我需要添加网格行和列定义以使其正常工作。

<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>
于 2015-01-27T16:48:17.557 回答
-2

这会将进度条拉伸到其容器

<StatusBarItem  Name="progressBarContainer">
    <ProgressBar Height="{Binding ElementName=progressBarContainer, Path=ActualHeight}" Width="{Binding ElementName=progressBarContainer, Path=ActualWidth}" Value="50" />
</StatusBarItem>
于 2014-07-23T18:14:14.243 回答