弹出窗口不显示 [英] Popup Not Showing

查看:126
本文介绍了弹出窗口不显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在点击事件中,我想在代码后面显示所有弹出窗口,但是我的弹出窗口没有显示吗?

On a tap event I would like to show a popup all within code behind, but my popup is not displaying?

void PopupDisplay_Tap(object sender, System.Windows.Input.GestureEventArgs e)
    {
        if (sender != null)
        {
            p = new Popup
            {
                Width = 480,
                Height = 580,
                HorizontalAlignment = System.Windows.HorizontalAlignment.Center,
                VerticalAlignment = System.Windows.VerticalAlignment.Center                    
            };

            Border b = new Border();
            b.BorderBrush = new SolidColorBrush(Colors.Gray);
            b.BorderThickness = new Thickness(2);
            b.Margin = new Thickness(10, 10, 10, 10);

            p.Child = b;
            p.IsOpen = true;
        }
    }

推荐答案

以为您试图通过顶级控件(如Pivot)弹出弹出窗口,

Think you're trying to Popup over a top-level control like a Pivot which is very buggy.

请参见带有枢轴的弹出框

如果它是Grid,它将弹出而没有问题.要解决此问题,您必须将其添加到与数据透视"相同的视觉级别,如下所示:

If it was a Grid, it would pop up without problem. To fix this you will have to add it to the same visual level as the Pivot like so:

<Grid x:Name="ContentPanel" Margin="0,0,0,0">
    <phone:Pivot x:Name="MainDisplay">
    <!-- more code -->
    </phone:Pivot>       
</Grid>

然后将其隐藏在您的代码中

Then in your code-behind

// I made with a thickness of 100, so we can see the border better
Popup p;

p = new Popup
{
    Width = 480,
    Height = 580,
    VerticalOffset = 0
};

Border b = new Border();
b.BorderBrush = new SolidColorBrush(Colors.Red);
b.BorderThickness = new Thickness(100);
b.Margin = new Thickness(10, 10, 10, 10);
b.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch;
b.VerticalAlignment = System.Windows.VerticalAlignment.Stretch;

p.Child = b;

// add it to the same level as the pivot to over ride pivot
this.ContentPanel.Children.Add(p);

p.IsOpen = true;

这篇关于弹出窗口不显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆