1

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;
        }
    }
Matthew
  • 3,976
  • 15
  • 66
  • 130

1 Answers1

1

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

See Popup with Pivots

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;
Community
  • 1
  • 1
Chubosaurus Software
  • 8,133
  • 2
  • 20
  • 26
  • 1
    Thanks what I ended up doing was defining the popup in XAML under my pivot control, but within the main grid. I then toggled the `IsOpen` property based on my needs and it worked. I appreciate your response. – Matthew Nov 03 '14 at 04:26