Reputation: 2771
I have an application running in landscape mode. I therefore wanted a popup showing when Applcation_activation was fired, so Authentication and data updating could happen in the background. But the problem is the app is running in landscape mode.
So if my application is starting when the phone is held in portrait mode, the popup will be shown like this. I therefore wanted to make sure the orientation was correct, and if not make a rotation manually in the code.
But I cannot access this.SupportedOrientation, so how do you display a popup from the event Application_activated?
A Solution A solution is of course to not use the event or simply set a flag and do the code in the navigatedTo event handlers for each page. But this is not a nive way to do it, when the event exists.
Anyy suggestion is appreciated
Screen Shots from two of my apps
Portrait
Landscape
popup
Basicly simple code.
Popup startup =new popup();
UsercontrolScreen childpopup =new UsercontrolScreen();
startup.child = childpopup;
startup.isOpen = true;
It is the same code for both, only the child is different.
Upvotes: 1
Views: 266
Reputation: 12465
If you are looking to add an overlay from within the App class, and always have it respect orientation, add it directly to the page content
private void Application_Activated(object sender, ActivatedEventArgs e)
{
var activePage = (PhoneApplicationPage) RootFrame.Content;
var pageContent = (Grid) activePage.Content;
UsercontrolScreen childpopup = new UsercontrolScreen();
Grid.SetRowSpan(childpopup , pageContent.RowDefinitions.Count);
pageContent.Children.Add(childpopup );
}
Using this approach you would need to remove the content as well. Maybe have an X button on the control that would remove itself, or maybe fire a Closed
event so the App could remove it from the grid. You would also need remove the control within the Deactivated event. Or, not add it again within the the Activated event if it was deactivated twice.
Upvotes: 1