DockPanel 中的 WPF4 TabControl/Grid 隐藏 StatusBar
我有一个窗口,其中充满了包含 3 个元素的 DockPanel、一个停靠在顶部的 MenuBar、一个停靠在底部的 StatusBar 和一个填充主体的 TabControl。
至少,我希望 TabControl 填充主体。在视觉设计器中,TabControl 和 StatusBar 并排放置,而不是顶部和顶部。底部。当我运行该应用程序时,TabControl 会展开以填充菜单栏下方的 DockPanel,并且 StatusBar 会消失。 (我猜它被推离了父窗口的可见画布。)
我尝试设置垂直和垂直方向。按照此建议进行水平对齐。 我尝试在状态栏上设置 ZIndex。 我尝试使用堆栈面板(都停靠在 DockPanel 内部并替换 DockPanel)。 一切都无济于事:-(
以下是我用来呈现 DockPanel 的 XAML 的摘录。对我做错了什么有什么建议吗?有没有比使用 DockPanel 更好的方法来做到这一点?
<DockPanel>
<Menu Name="_menu" Height="23" HorizontalAlignment="Stretch" VerticalAlignment="Top" DockPanel.Dock="Top">
<MenuItem Header="_User Maintenance">
</MenuItem>
</Menu>
<TabControl
x:Name="_panel"
ItemsSource="{Binding Path=AllTabs}"
Margin="0,0,0,0"
Visibility="{Binding Path=Visibility}"
DockPanel.Dock="Top"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
>
</TabControl>
<StatusBar Name="_statusBar" DockPanel.Dock="Bottom" Margin="0,0,0,0" VerticalAlignment="Bottom">
<StatusBar.ItemsPanel>
<ItemsPanelTemplate>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="26"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
</Grid>
</ItemsPanelTemplate>
</StatusBar.ItemsPanel>
<StatusBarItem Grid.Column="0" Grid.Row="0">
<ProgressBar Name="_progressBar" Height="20" IsIndeterminate="True" Margin="4,0,4,0" VerticalAlignment="Top" Width="600"/>
</StatusBarItem>
</StatusBar>
</DockPanel>
编辑:
通过将 DockPanel.Dock="Top" 添加到 TabControl 以及 HorizontalAlignment 和 HorizontalAlignment 中。 VerticalAlignment="Stretch",我能够在可视设计器中将 TabControl 堆叠在 StatusBar 上方而不是旁边。现在,对于我的某些 TabItem,状态栏仅在运行时消失。
我的 TabControl 数据绑定到公开 UserControls 列表的 ViewModel。每个 UserControl 都包含其自己的数据绑定 DataGrid(通常还有一些其他控件)。在 DataGrid 仅显示几行的那些选项卡中,TabControl 和TabItem 仅拉伸以包含 UserGrid,而使 StatusBar 在页面底部可见。在 DataGrid 显示多行的选项卡上,TabControl 会拉伸以填充窗口,以某种方式隐藏 StatusBar。
如果有帮助,这是我的 DataGrid 定义:
<DataGrid
Name="_customerGrid"
Grid.Column="0"
Grid.ColumnSpan="3"
Grid.Row="1"
AutoGenerateColumns="False"
CanUserSortColumns="True"
ColumnHeaderStyle="{StaticResource columnHeaderStyle}"
HorizontalAlignment="Left"
ItemsSource="{Binding Path=AllCustomers}"
RowDetailsVisibilityMode="VisibleWhenSelected"
RowStyle="{StaticResource DataGridRowStyle}"
SelectionUnit="FullRow"
VerticalAlignment="Top">
谢谢!
I have a window filled with a DockPanel containing 3 elements, a MenuBar docked at the top, a StatusBar docked at the bottom and a TabControl filling the body.
At least, I would like the TabControl to fill the body. In the visual designer, the TabControl and StatusBar are laid out side by side instead of top & bottom. When I run the application, the TabControl expands to fill the DockPanel below the MenuBar and the StatusBar disappears. (I am guessing it is being pushed off the visible canvas of the parent window.)
I tried setting vertical & horizontal alignment per this recommendation.
I tried setting ZIndex on the StatusBar.
I tried using a stack panel (both docked inside the DockPanel and replacing the DockPanel).
All to no avail :-(
Following is an extract of the XAML I'm using to render my DockPanel. Any suggestions on what I'm doing wrong? Is there a better way to do this than using a DockPanel?
<DockPanel>
<Menu Name="_menu" Height="23" HorizontalAlignment="Stretch" VerticalAlignment="Top" DockPanel.Dock="Top">
<MenuItem Header="_User Maintenance">
</MenuItem>
</Menu>
<TabControl
x:Name="_panel"
ItemsSource="{Binding Path=AllTabs}"
Margin="0,0,0,0"
Visibility="{Binding Path=Visibility}"
DockPanel.Dock="Top"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
>
</TabControl>
<StatusBar Name="_statusBar" DockPanel.Dock="Bottom" Margin="0,0,0,0" VerticalAlignment="Bottom">
<StatusBar.ItemsPanel>
<ItemsPanelTemplate>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="26"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
</Grid>
</ItemsPanelTemplate>
</StatusBar.ItemsPanel>
<StatusBarItem Grid.Column="0" Grid.Row="0">
<ProgressBar Name="_progressBar" Height="20" IsIndeterminate="True" Margin="4,0,4,0" VerticalAlignment="Top" Width="600"/>
</StatusBarItem>
</StatusBar>
</DockPanel>
Edit:
By adding DockPanel.Dock="Top" to the TabControl along with both HorizontalAlignment & VerticalAlignment="Stretch", I was able to get the TabControl to stack above the StatusBar instead of next to it in the visual designer. Now, the StatusBar only disappears at runtime for some of my TabItems.
My TabControl is databound to a ViewModel that exposes a list of UserControls. Each UserControl contains its own databound DataGrid (and usually a few other controls). In those tabs for which the DataGrid only displays a few rows, the TabControl & TabItem only stretch to contain the UserGrid, leaving the StatusBar visible at the bottom of the page. On those tabs where the DataGrid shows many rows, the TabControl stretches to fill the window, somehow hiding the StatusBar.
In case it helps, here is my DataGrid definition:
<DataGrid
Name="_customerGrid"
Grid.Column="0"
Grid.ColumnSpan="3"
Grid.Row="1"
AutoGenerateColumns="False"
CanUserSortColumns="True"
ColumnHeaderStyle="{StaticResource columnHeaderStyle}"
HorizontalAlignment="Left"
ItemsSource="{Binding Path=AllCustomers}"
RowDetailsVisibilityMode="VisibleWhenSelected"
RowStyle="{StaticResource DataGridRowStyle}"
SelectionUnit="FullRow"
VerticalAlignment="Top">
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
DockPanel 取决于项目的添加顺序。您必须先添加停靠的项目,然后再添加占用剩余空间的项目。就您而言,您只需将项目重新排列为如下所示:
DockPanel depends on the order in which the items are added. You'll have to add the docked items first before adding the item that takes up the remaining space. In your case, you'll just have to rearrange your items to something like this: