避免 WPF 状态栏在窗口垂直调整大小时增加其高度
Posted
技术标签:
【中文标题】避免 WPF 状态栏在窗口垂直调整大小时增加其高度【英文标题】:Avoid WPF Statusbar to increase its height on window vertical resize 【发布时间】:2019-06-04 13:47:18 【问题描述】:我有一个 WPF 状态栏,我通过执行以下操作将它放在底部:
<Window>
<DockPanel>
<Grid DockPanel.Dock="Top">
<!-- Grid stuff here -->
</Grid>
<StatusBar DockPanel.Dock="Bottom"
VerticalAlignment="Stretch">
<StatusBar.ItemsPanel>
<ItemsPanelTemplate>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="100" />
</Grid.ColumnDefinitions>
</Grid>
</ItemsPanelTemplate>
</StatusBar.ItemsPanel>
<StatusBarItem Grid.Column="0">
<TextBlock Text="Item1"/>
</StatusBarItem>
<Separator Grid.Column="1" />
<StatusBarItem Grid.Column="2">
<TextBlock />
</StatusBarItem>
<Separator Grid.Column="3" />
<StatusBarItem Grid.Column="4">
<TextBlock Text="AnotherItem" />
</StatusBarItem>
</DockPanel>
</Window>
问题是当用户垂直调整窗口大小时,状态栏会增加它的高度,我想避免这种情况。我希望状态栏始终保持其高度(相同)。我该怎么做?
【问题讨论】:
【参考方案1】:尝试在状态栏上设置 VerticalAlignment= Bottom。这是您的新代码。
<DockPanel>
<Grid DockPanel.Dock="Top">
<!-- Grid stuff here -->
<ListView></ListView>
</Grid>
<StatusBar DockPanel.Dock="Bottom"
VerticalAlignment="Bottom">
<StatusBar.ItemsPanel>
<ItemsPanelTemplate>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="100" />
</Grid.ColumnDefinitions>
</Grid>
</ItemsPanelTemplate>
</StatusBar.ItemsPanel>
<StatusBarItem Grid.Column="0">
<TextBlock Text="Item1"/>
</StatusBarItem>
<Separator Grid.Column="1" />
<StatusBarItem Grid.Column="2">
<TextBlock />
</StatusBarItem>
<Separator Grid.Column="3" />
<StatusBarItem Grid.Column="4">
<TextBlock Text="AnotherItem" />
</StatusBarItem>
</StatusBar>
</DockPanel>
【讨论】:
以上是关于避免 WPF 状态栏在窗口垂直调整大小时增加其高度的主要内容,如果未能解决你的问题,请参考以下文章
WPF:如何在弹出窗口中自动调整 WebBrowser 的大小?