question

njsokalski avatar image
0 Votes"
njsokalski asked ·

Microsoft Emulator: What triggers the SizeChanged event?

When using the Microsoft Emulator for a UWP app, I have noticed that the SizeChanged event is not always triggered if the device is rotated. For example, if the device has the 2 screens above/below each other and my app is single screen on the top, rotated 90 counterclockwise, when I click the Rotate Right button, the device screens become side by side with my app on the right, unrotated. This does not trigger the SizeChanged event. My basic goal is to have my app be ALWAYS right side up (which means it would never have been rotated 90 to begin with), and be able to span 1 or 2 screens. But if SizeChanged (or any other event I could find) is not always triggered for scenarios like this, how can I determine when to rearrange my layout? Will the actual device always trigger events the same way as the Microsoft Emulator? With previous devices I have developed for, the device would always (unless the code explicitly stated otherwise) display the app right side up. Can anybody help me? Thanks.

windows-uwp
· 5
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Are you sure you are handling the Window.SizeChanged event not one on a framework element?

0 Votes 0 ·

The event is handling the SizeChanged event of a Page (it inherits from the Page class, just like most UWP apps). I declare the event handler as follows:

 Private Sub MainPage_SizeChanged(sender As Object, e As SizeChangedEventArgs) Handles Me.SizeChanged

Unless Window.SizeChanged works differently a Page (which I strongly doubt), I doubt that is the problem. Any other ideas?

0 Votes 0 ·

When either the ActualHeight or the ActualWidth property changes value, the SizeChanged event will be triggered. When you rotate the device, the ActualHeight and ActualWidth are not always changed. In addition, based on your description, do you want to trigger an event when the device is rotated? In addition, I'm also confused about "My basic goal is to have my app be ALWAYS right side up", do you mean you don't want the app itself to be rotated during device rotation? Can you please show more details about your expected behavior?

0 Votes 0 ·

I do need an event when the device is rotated. You say "When you rotate the device, the ActualHeight and ActualWidth are not always changed." Does that mean that, for example, ActualHeight is sometimes the horizontal value? When I say "My basic goal is to have my app be ALWAYS right side up", I mean that I want the left of the app to match the left of the user, etc. I also noticed while taking screenshots (which is why I did not include any) that the orientation of the screenshots did not always match the orientation of the device. The screenshots always had the screens side by side, regardless of the device orientation. You say that SizeChanged is based on ActualWidth & ActualHeight, so this made me wonder if the emulator is basing SizeChanged on the ActualWidth & ActualHeight of the device or the screenshot.

0 Votes 0 ·

Yeap, when rotating the device, the ActualHeight is sometimes the horizontal value, you can check the value. In addition, you could use SimpleOrientationSensor class and subscribe its OrientationChanged event to listen the rotation of the device.


1 Vote 1 ·

1 Answer

njsokalski avatar image
0 Votes"
njsokalski answered ·

Thank you so much! I think by using the combination of SizeChanged & OrientationChanged (since it seems some of the properties such as ActualWidth & ActualHeight have not yet been updated when OrientationChanged is triggered) I can accomplish everything I need. Thank you again for all your help!

·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.