How to execute code before starting to change orientation?

Asked

Viewed 42 times

1

I’m wondering if there’s any event or way to run a piece of code before it happens to change directions on Windows Phone. My problem is I need to close one MenuFlyout before changing orientation, otherwise the application breaks. Someone knows how to get around this problem?

1 answer

1


I do something similar. When the page orientation is changed I close a panel in my application. I do this in the event fired when the orientation of the device changes.

public MainPage()
{
   InitializeComponent();
   this.OrientationChanged += OnOrientationChanged;
}

private void OnOrientationChanged(object sender, OrientationChangedEventArgs e)
{
   var orientação = e.Orientation;
}

PageOrientation

View documentation here

EDIT

Windows Phone doesn’t have an event with an easy name for you to identify that indicates this event will be triggered before the screen orientation is changed, but there is this event.

Beginlayoutchanged event is triggered before the phone orientation is changed.

BeginLayoutChanged += (o, args) => MessageBox.Show("Antes de Mudar");
OrientationChanged += (o, args) => MessageBox.Show("Depois de Mudar");

More information about the event here

  • Some problems: I know I didn’t say, but it is windows phone 8.1 RT, it only serves for Silverlight. Still, even if it were the case, that code is executed later the exchange of guidance. :/

  • Please see the reply update.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.