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的中心部分,但它只显示几个像素的宽度。有什么想法吗?
答案 0 :(得分:8)
这是由于StatusBar
默认使用DockPanel
来布置其子项。请参阅我的问题并回答here。
答案 1 :(得分:5)
您需要使用网格。 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>
答案 2 :(得分: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>
答案 3 :(得分:-2)
这会将进度条拉伸到其容器
<StatusBarItem Name="progressBarContainer">
<ProgressBar Height="{Binding ElementName=progressBarContainer, Path=ActualHeight}" Width="{Binding ElementName=progressBarContainer, Path=ActualWidth}" Value="50" />
</StatusBarItem>