Fix orientation of uwp app - windows 10 - c#

Irrespective of the orientation of device my app should run in portrait mode only.
Every page except only one page should run on the landscape.
How can I achieve this?
I tried below things:
On manifest file, I have checked supported rotation to "portrait" only.
And written below code on the page I need to show in a landscape,
protected override async void OnNavigatedTo(NavigationEventArgs e)
{
DisplayInformation.AutoRotationPreferences = DisplayOrientations.Landscape | DisplayOrientations.LandscapeFlipped;
}
But when run with simulator, it works in both portrait and landscape mode. What is the reason for it?
I have to rotate the simulator to 90 degree for seeing the app in portrait mode.

If you check the DisplayOrientations Enum document, you could see the remark shows:
Applications typically use this property to translate the reading of an accelerometer or to translate the physical button events in accordance with the current screen rotation.
It means that it has no effect on simulator. Besides, Auto-rotation also will be turned on by the user.
Please see the similar thread for more details:How to enable only landscape mode in a UWP app?

Related

Ipad resolution for landscape and portrait - Xamarin ios

I am relatively new to Xamarin ios and am creating an application that
will work in both Landscape and Portrait for both iPhone and iPad.
I have been able to implement both Landscape and portrait on iPhone pretty fine by using a rotation callback method that will invoke a different view with the same layout but adjusted dimensions for the landscape version and on the landscape version I have the same to go back to portrait. This works okay but has some lag at times.
I'm not very sure about what is the right way to present two different UIs for different orientations. If anyone has any suggestions please let me know.
Now I have a list that holds values for Height and Width of the current device and I will devise this by the current device density like so:
maindisplayinfo.height / maindisplayinfo.density
and this gives me the current display dimensions I need. I use this to place my objects relative to a screen portion such as:
CGRect(0, Height * 0.30, Image.Bounds.Width, Image.Bounds.Height)
On rotation on Ipad, the display goes funny even though I have set dimensions correctly and my rotation callback triggers the different views. Not sure what is going on here.
But is there a certain way to do this sort of thing with iPad and iPhone?

WPF Issues Creating Window on Secondary Screen Only On Certain Hardware Configurations

I'm using the standard recommendation for creating a Window and having it display on a secondary monitor:
I use the following to get the screens available:
Screen[] availableScreens = Screen.AllScreens;
Extract the working area of the target screen (second screen in my case, not the primary screen):
secondaryScreenWorkingArea = availableScreens[1].WorkingArea;
When creating the window, set the location properties based on the working area (before calling Show()):
Left = secondaryScreenWorkingArea.Left;
Top = secondaryScreenWorkingArea.Top;
Width = secondaryScreenWorkingArea.Width;
Height = secondaryScreenWorkingArea.Height;
Some other things to note about the window:
It is a fullscreen window that is intended to span the entire second
display
It is not the main application window
It is hidden from the taskbar, it is intended to be supplemental to
the main application window
WindowState = WindowState.Maximized;
ShowInTaskbar="False"
WindowStyle = WindowStyle.None;
Running on Windows 10 Enterprise V 1809
Below is a rundown is different configurations that I've tested, and only one of them is not behaving correctly:
When I run this on a workstation setup with two 1920x1080 displays, 100% display scaling, it works as expected.
When I run this on a workstation setup with two 1920x1080 displays, 150% display scaling, it works as expected.
When I run this on a workstation setup with a 1920x1080 display and a secondary USB display (800x480) connected, 100% display scaling, it works
When I run this on a workstation setup with a 1920x1080 display and a secondary USB display (800x480) connected, 150% display scaling, it works
When I run this on a Microsoft Surface Go with the main surface display (1800x1200) and a secondary USB display (800x480) connected to the surface dock, 100% display scaling, it works
When I run this on a Microsoft Surface Go with the main surface display (1800x1200) and a secondary USB display (800x480) connected to the surface dock, 150% display scaling, it DOES NOT work. Instead, once Window.Show() is called, this is triggering the window to relocate to the primary display (The surface go screen). I noticed this because I am receiving a LocationChanged event for the window during my call to Window.Show() and see the Width and Height properties have updated to the sizing of the Surface Go display (1800x1200). But, curiously, the Top and Left properties are NOT updated even though the window has moved.
As you can see from the cases above, it seems to be an issue with Display scaling + the Surface Go. On my workstation, I forced the same resolution as the Surface go (1800x1200) and set display scaling to 150%, but could not replicate the issue from the Surface Go
Furthermore, I performed some testing with another USB display with a slightly higher resolution (1024x600) and have noticed that the same issue occurs, only on the Surface Go, but this time it required me pushing the display scaling to 200% before the issue began to occur in that configuration.
Several things I've tried, but none produced any solutions to this issue:
Tried various configurations of dpiAware and dpiAwareness. These changed the scaling of the coordinates I received when grabbing the AvailableScreens, but using scaled/unscaled coordinates had not affect on this issue
Restarting the Surface Go after changing the display scaling option (per the "Some apps won't respond to scaling changes until you sign of" message displayed in the Display Settings
Tried setting WindowState = WindowState.Maximized both before and after the Loaded event and both yielded the same result.
Any help or other ideas for things to try would be appreciated, not sure if this is a WPF, Windows 10 or a Microsoft Surface Go issue.

How do you set Windows CE 6.5 to landscape only using C#?

I am writing an application for Windows CE 6.5 in C#. The device will be mounted on a wrist strap so will always be in the landscape position, so I have designed the app accordingly. The problem is when you move the device when working the device switches between Portrait and Landscape. This is quite annoying and will also defeat the purpose of the program as it will slow down the users if they have to wait for the device to switch to landscape every time they want to use it.
I have researched this but have not found a working solution. I know in previous versions of CE you can set Right Handed/ Left Handed Landscape but I have checked and that option is nowhere to be found on this device.
Is there any way of programatically setting the orientation so that it does not change?
Thanks In Advance

Landscape only iPad application using Mono Touch

I'm using Mono Touch to develop a landscape-only iPad application but the simulator doesn't seem to rotate any of the views (or the main window for that matter) to landscape.
I've set the SDK version and Minimum OS version to 4.2.
I have also set the Supported Orientations to Landscape.
Furthermore, I've created a Navigation Controller which overrides the ShouldAutorotateToInterfaceOrientation and sets it to return true. I then added it using window.AddSubview(navigationController.View) but that didn't help either.
I'm using the Rotate Left/Right methods (under Hardware) in the simulator but the whole app rotates with the window and the app stays in Portrait mode. Even the status bar (carrier, time, battery) go off to the right instead of moving up to the top of the screen.
Help?! Anyone?!
Have you set the UIInterfaceOrientation key to landscape as well?
Also, in shouldAutorotateToInterfaceOrientation you'll want to only return true if the new orientation matches the orientation you want.

Windows Mobile 6.x How to explicitly lock the app in one orientation?

I'm trying to get an app on the WinMo App Store.
As part of this, Microsoft App's Store has asked that I need to support landscape as well as portrait.
What they've said is OK is:
If dynamic switching is implicitly allowed, the
app will be tested just as if it
supports both portrait and landscape
even if only a portrait or landscape
resolution is checked.
You may explicitly lock the app in one orientation (which means
portrait mode if the app does not
handle landscape mode functions), provided the default OS orientation is preserved once the app exits.
I'd love to do answer 2 - but I can't find any way of doing it - and they won't provide me any other clues - they suggested I ask on the forums... so here I am on Stack Overflow - far better than on the forums :)
Anyone got any suggestions?
This should be simple enough, the details of how to handle portrait to landscape orientation change are provided here. That articles recommend repositioning layouts, buttons etc. So, for the app to remain in portrait mode only, when it receives WM_SIZE notification, dont change the display at all.
One more thing, it is a better user experience if you can display a message asking user to go back to portrait mode to use the app. Otherwise its a bit disorienting, as most apps nowadays handle orientation change seemlessly.

Categories