在WPF中显示网格中其他控件的控件
我正在开发WPF应用程序。在WPF中显示网格中其他控件的控件,wpf,layout,overlay,Wpf,Layout,Overlay,我正在开发WPF应用程序。 主窗口的子控件包含在网格中。 最下面一行包含一个状态栏 应用程序必须通知用户。 我想以编程方式在主窗口右下角的用户控件中显示通知。 我希望通知用户控件显示在状态栏和上行中的控件上 如何将控件显示在网格中包含的其他控件之上? 任何帮助都将不胜感激。网格有一个名为ZIndex的属性。看看这个例子: <Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" WindowTitle="
主窗口的子控件包含在网格中。
最下面一行包含一个状态栏 应用程序必须通知用户。
我想以编程方式在主窗口右下角的用户控件中显示通知。
我希望通知用户控件显示在状态栏和上行中的控件上 如何将控件显示在网格中包含的其他控件之上?
任何帮助都将不胜感激。网格有一个名为ZIndex的属性。看看这个例子:
<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" WindowTitle="ZIndex Sample">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Rectangle Grid.Row="0" Grid.ZIndex="3" Fill="blue"/>
<Rectangle Grid.Row="0" Grid.ZIndex="1" Fill="yellow"/>
<Rectangle Grid.Row="0" Grid.ZIndex="2" Fill="green"/>
<!-- Reverse the order to illustrate z-index property -->
<Rectangle Grid.Row="1" Grid.ZIndex="1" Fill="green"/>
<Rectangle Grid.Row="1" Grid.ZIndex="3" Fill="yellow"/>
<Rectangle Grid.Row="1" Grid.ZIndex="2" Fill="blue"/>
</Grid>
如果未指定ZIndex,则面板的子控件将按照指定的顺序(即位于顶部的最后一个)进行渲染。或者,您可以使用(始终位于其他控件的顶部)。当您想要显示一些更新时,将其切换为等参状态
<Popup IsOpen="True">
<TextBlock Text="Important update!!" Background="White" Foreground="Black"></TextBlock>
</Popup>
有几种方法可以将弹出窗口粘贴到右下角的位置-Dockpanel、stackpanel(右对齐)、Grid。网格的示例如下所示:
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"></ColumnDefinition>
<ColumnDefinition Width="Auto"></ColumnDefinition>
</Grid.ColumnDefinitions>
<StackPanel Grid.Row="0" Grid.ColumnSpan="2">
<!--Place any control here-->
</StackPanel>
<StackPanel x:Name="BottomRightPanel" Grid.Row="1" Grid.Column="1">
<Popup IsOpen="True" Placement="">
<TextBlock Text="Important update!!" Background="White" Foreground="Black"></TextBlock>
</Popup>
</StackPanel>
</Grid>
我已经解决了我的问题。
我已经修改了主窗口的XAML标记。
我已经在新网格的同一单元格中声明了通知用户控件和包含主窗口子控件的网格 我在通知用户控件的开始标记中设置了一些属性:
- Grid.ZIndex=“1”
- 水平对齐=“右”
- 垂直对齐=“底部”
- 保证金=“0 20 20”
- 通知用户控件位于包含主窗口子控件的网格上
- 通知用户控件位于主窗口的右下角
- 试试这个
使用Panel.ZIndex可以实现这一点
ZIndex实际上是WPF中面板上的一个附加属性,也被其他重叠布局面板(如Canvas)使用。@JohnBowen感谢您提供的信息。我会记住的。@Vishal我不能将状态栏和通知用户控件放在同一行上。通知用户控件的高度将大于状态栏的高度。通知用户控件必须与最下面一行重叠,并且部分位于上面的控件之上。我已经阅读了有关弹出窗口放置的MSDN文档,但没有找到如何将弹出窗口放置在主窗口的右下角。我该怎么做?@user1139666尝试在弹出窗口上使用HorizontalAlignment=“Right”
和VerticalAlignment=“Bottom”
。更新了上面的答案。根据我的经验,Popup
创建了一个单独的Win32窗口,而不是当前窗口中的覆盖,这不是我想要的,因为弹出窗口没有跟随主窗口。
<Expander Name="expander_options" Header="Options" Margin="330,10,0,182" Panel.ZIndex="1">
<StackPanel Margin="10,4,0,0" Panel.ZIndex="2" Background="Aqua">
<CheckBox Margin="4" Content="Option 1" />
<CheckBox Margin="4" Content="Option 2" />
<CheckBox Margin="4" Content="Option 3" />
</StackPanel>
</Expander>