弹出窗口没有显示

时间:2014-11-02 15:51:41

标签: c# windows-phone-8 popup

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

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;
        }
    }

1 个答案:

答案 0 :(得分:1)

认为你正在尝试弹出一个顶级控件,就像Pivot一样非常错误。

请参阅Popup with Pivots

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

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

然后在你的代码隐藏

// 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;