Haider
Haider

Reputation: 1488

windows phone 8 popup width and height

I am placing a grid in a popup control. I expected the grid to be re-sized automatically according to the 3 different layout sizes for windows phone 8 apps (480 × 800, 768 × 1280, 720 × 1280).

But it seems like i would have to set the width and height of the grid explicitly because it's re-sizing itself according to child control size whereas i wanted the popup box to be shown as full with on the top of the screen for all three resolutions.

Any Help?

Upvotes: 3

Views: 9784

Answers (1)

JustinAngel
JustinAngel

Reputation: 16102

The easiest way to get a full screen popup to work on WP8 is by setting the Child width & height to the phone's current logical resolution. You can read more about WP8 Multi-resolution zen here and learn more about WP8 Multi-resolution APIs here.

private void Button_Click_1(object sender, RoutedEventArgs e)
{
    var myPopup = new Popup()
    {
        Child = new Border()
        {
            Child = new TextBlock()
                    {
                        Text = "Hello World!"
                    },
            Height =  Application.Current.Host.Content.ActualHeight,
            Width =  Application.Current.Host.Content.ActualWidth,
            Background = new SolidColorBrush(Colors.Green)
        }
    };

    this.LayoutRoot.Children.Add(myPopup);
    myPopup.IsOpen = true; 
}

This code snippet is a bit overzealous since shell items (e.g. SystemTray, AplicaitonBar, etc) can take space away from your rendering area.

Here's a print screen of the code snippet above executing in the WXGA emulator:

Full screen popup on WXGA

And here's the code snippet above executing in the 720P emulator: Full screen popup on 720P

Upvotes: 29

Related Questions