StatusBar 中的 WPF ProgressBar 不会拉伸
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16173343/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
WPF ProgressBar in StatusBar won't stretch
提问by RedEyedMonster
New to WPF & I have the following XAML
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>
I want the ProgressBar to fill the centre portion of the StatusBar but it only shows itself a few pixels in width. Any ideas?
我希望 ProgressBar 填充 StatusBar 的中心部分,但它只显示几个像素的宽度。有任何想法吗?
回答by Kent Boogaart
回答by Jeff
You will need to use a Grid. A DockPanel or StackPanel will not suffice for you. Try:
您将需要使用网格。一个 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>
回答by Scott Shaw-Smith
This helped me, but I needed to add Grid Row and Column Definitions to make it work properly.
这对我有帮助,但我需要添加网格行和列定义以使其正常工作。
<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>
回答by fab
This stretches the progress bar to its container
这会将进度条拉伸到其容器
<StatusBarItem Name="progressBarContainer">
<ProgressBar Height="{Binding ElementName=progressBarContainer, Path=ActualHeight}" Width="{Binding ElementName=progressBarContainer, Path=ActualWidth}" Value="50" />
</StatusBarItem>

