为什么WPF进度条不适合?

Joh*_*ies 8 wpf alignment stackpanel

这是我的原始代码:

<StackPanel Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="2" Orientation="Horizontal">
        <ProgressBar Height="23" Name="searchProgressBar" Foreground="Blue" BorderBrush="#00000000" BorderThickness="1" VerticalAlignment="Top" HorizontalAlignment="Stretch"/>
        <TextBlock Text="asdf" Height="23"  Name="progressTextBlock" VerticalAlignment="Top" Foreground="Red" HorizontalAlignment="Right"/>
</StackPanel>
Run Code Online (Sandbox Code Playgroud)

进度条非常小,可能是2或3像素宽,然后是文本块和空白区域.所以我尝试将元素明确地对接到两侧:

<DockPanel Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="2" >
            <ProgressBar DockPanel.Dock="Left" Height="23" Name="searchProgressBar" Foreground="Blue" BorderBrush="#00000000" BorderThickness="1" VerticalAlignment="Top" />
            <TextBlock DockPanel.Dock="Right" Text="asdf" Height="23"  Name="progressTextBlock" VerticalAlignment="Top" Foreground="Red" HorizontalAlignment="Right"/>
</DockPanel>
Run Code Online (Sandbox Code Playgroud)

徒劳无功.我也尝试通过设置HorizontalAlignment="Stretch"进度条修改每个解决方案,但没有变化.在渲染文本块后,如何拉伸它以填充所有空间?

Adi*_*ter 5

DockPanel.Dock="Left"从 中删除ProgressBar并切换控件的顺序:

<DockPanel>
    <TextBlock DockPanel.Dock="Right" Height="23"  VerticalAlignment="Top" HorizontalAlignment="Right"/>
    <ProgressBar Height="23" VerticalAlignment="Top" />
</DockPanel>
Run Code Online (Sandbox Code Playgroud)

默认情况下,DockPanel其属性LastChildFill设置为true,这将使占用ProgressBar可用空间。