【问题标题】:How to set Popup panel index that will overlay other controls in WPF?如何设置将覆盖 WPF 中其他控件的弹出面板索引?
【发布时间】:2017-03-03 00:26:38
【问题描述】:

我有一个关于如何正确设置网格内弹出窗口的 Panel.ZIndex 的问题。目标是,当我单击紧急按钮时,将显示一个弹出窗口,上面有一个图像并覆盖(覆盖)按钮(见下面的截图)。

我已将 Grid Panel.ZIndex="0" 和 Popup 设置为 Panel.ZIndex="1" 但是,Popup 窗口不会覆盖按钮。

这是 XAML 实现。

<StackPanel Background="Black">
    <Grid Background="#253341" Panel.ZIndex="0">
        <Popup HorizontalOffset="-5" VerticalOffset="0" IsOpen="False" 
               HorizontalAlignment="Left" VerticalAlignment="Top"
               Name="EmergencyPopup" Placement="RelativePoint" AllowsTransparency="True"
               PlacementTarget="{Binding ElementName=EmergencyButton}"
               Width="1080" Height="1920" Panel.ZIndex="1">
            <Border BorderBrush="Black" BorderThickness="2" CornerRadius="2">
                <Grid>
                    <Image Source="{StaticResource EdenParkInfoImg}"/>
                    <Label FontWeight="Bold" Foreground="Red" HorizontalAlignment="Right" FontSize="25"
                           MouseLeftButtonDown="Label_MouseLeftButtonDown">close X</Label>
                </Grid>
            </Border>
        </Popup>
    </Grid>
</StackPanel>

Popup窗口和按钮的截图(红框表示Popup里面的图片在按钮后面)

我是否正确设置了 Grid 和 Popup 的 Panel.ZIndex?正确的做法是什么?

非常感谢任何帮助。

【问题讨论】:

  • 你能在上图中标出哪个是弹出窗口吗?
  • @SatyajitMohanty,弹出对话框是您看到的大图。请看这张图片link。绿色框中的突出显示是弹出对话框。而在 xaml 中,Popup 的名称是 EmergencyPopup。
  • @SatyajitMohanty,您知道如何将弹出窗口的 ZIndex 设置在其他控件(即紧急信息、反馈、辅助功能按钮)之上吗?
  • @Juniuz 它应该可以在不定义 ZIndex 的情况下工作,您确定在单击紧急按钮时将 isopen 设置为 true 吗?
  • @Juniuz 请显示您的Page/Window的完整标记

标签: c# wpf xaml


【解决方案1】:

我确实找到了解决问题的方法。在我的弹出对话框 xaml 实现中,我将 Horizo​​ntalOffset 设置为 0,将 VerticalOffset 设置为 180。这样,弹出对话框垂直覆盖按钮,ZIndex 不再重要。 WPFUser 是对的,它应该在没有明确定义 ZIndex 的情况下工作。

<Popup HorizontalOffset="0" VerticalOffset="180" IsOpen="False" Width="1080" 
                       HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Height="1920"
                       Name="EmergencyPopup" Placement="Top" AllowsTransparency="True">
                    <Border BorderBrush="Black">
                        <Grid>
                        <Image Source="{StaticResource EdenParkInfoImg}" />
                        <Label FontWeight="Bold" Foreground="Red" HorizontalAlignment="Right" FontSize="25"
                               MouseLeftButtonDown="Label_MouseLeftButtonDown" Margin="0,0,15,0">close X
                        </Label>
                        </Grid>
                    </Border>
                </Popup>

【讨论】:

    猜你喜欢
    • 2011-01-02
    • 2016-04-27
    • 2017-12-01
    • 1970-01-01
    • 2011-02-23
    • 1970-01-01
    • 2019-06-26
    • 2011-07-23
    • 2011-12-26
    相关资源
    最近更新 更多