mastiSoft
asked on
Switch between Landscape or Portrait mode
hi.
How do I know if the tablet is in Landscape or Portrait mode?
I have an application written in WPF (C#) , the layout looks nice if the tablet is Landscape mode, but for Portrait mode I have to use another layout.
How do I get know app. when layout have to be switched from one to another?
How do I know if the tablet is in Landscape or Portrait mode?
I have an application written in WPF (C#) , the layout looks nice if the tablet is Landscape mode, but for Portrait mode I have to use another layout.
How do I get know app. when layout have to be switched from one to another?
ASKER
Hi, thank you for the answer David.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
There are events which are fired when the display settings change; e.g. -
Microsoft.Win32.SystemEvents.DisplaySettingsChanged += new
EventHandler(OnDisplaySettingsChanged);
public bool IsLandscape { get; set; }
void OnDisplaySettingsChanged(object sender, EventArgs e)
{
IsLandscape = SystemParameters.PrimaryScreenWidth > SystemParameters.PrimaryScreenHeight;
RaisePropertyChanged( "IsLandscape" );
}
Main Window.xaml -
<Border >
<Border.Style>
<Style TargetType="{x:Type Border}">
<Style.Triggers>
<DataTrigger Binding="{Binding IsLandscape}" Value="True">
<Setter Property="LayoutTransform">
<Setter.Value>
<RotateTransform Angle="90"/>
</Setter.Value>
</Setter>
</DataTrigger>
</Style.Triggers>
</Style>
</Border.Style>
///The rest of your controls and UI
</Border>
-saige-
ASKER
thank you to all for suggestions. I will test all of them and give my answer tomorrow.
You can't.Ummm... Doesn't landscape mode simply mean that the width is greater than the height (and vice versa)?
All you can know, at any given point, are screen dimensions.
Or in other words, line 8 of it_saige's first snippet?
All you can know, at any given point, are screen dimensions.
And even screen dimensions can change instantly, as someone rotates their device.
The easy way to deal with this is to use @media directives with CSS breakpoints for different devices.
So you'll never write code for landscape or portrait, you'll write code for a specific CSS breakpoint, which can change at any time.