In .NET MAUI is there a way to choose a different XAML view based upon whether the device is in Landscape or Portrait - xaml

I am using .NET MAUI and I have a particular view that is rather complicated and I would rather have a different layout if the device orientation is in Portrait vs if the device orientation is in landscape.
I tinkered around with Android programming a long time ago and for Android Studio there was a way to choose a XAML file when the device was in landscape and a different XAML file when the device was in portrait.
Is this possible with MAUI?
If not what is the best practice in regards to this?
Here is my layout and in landscape mode I can fit 3 major sections in one row but this won't work in portrait and in portrait I would like the middle major element to be on the next row.
Here are examples of my portrait vs landscape mockup I created on Photoshop:
UPDATE WITH SOLUTION***************
I'm attempting the solution that FreakyAli posted and have a mostly working prototype, so anyone who is wanting to use a different XAML layout based upon the screen orientation can use this approach.
I created a new folder called "ContentViews" in my solution.
I added 3 new ContentViews (the XAML with the code behind):
HomePageLandscape
HomePagePortrait
HomePageOrientationViewLoader
The HomePageOrientationViewLoader will get loaded directly into the HomePage.xaml file later on. This is the control that will load either the HomePagePortrait ContentView when in portrait mode or HomePageLandscape ContentView when in landscape mode.
namespace ScoreKeepersBoard.ContentViews;
public partial class HomePageOrientationViewLoader : ContentView
{
public ContentView homePagePortraitContentView;
public ContentView homePageLandscapeContentView;
public HomePageOrientationViewLoader()
{
InitializeComponent();
homePagePortraitContentView = new HomePagePortrait();
homePageLandscapeContentView = new HomePageLandscape();
this.Content = homePageLandscapeContentView;
DeviceDisplay.Current.MainDisplayInfoChanged += Current_MainDisplayInfoChanged;
this.Content = DeviceDisplay.Current.MainDisplayInfo.Orientation == DisplayOrientation.Portrait ? homePagePortraitContentView : homePageLandscapeContentView;
}
private void Current_MainDisplayInfoChanged(object sender, DisplayInfoChangedEventArgs e)
{
if (e.DisplayInfo.Orientation == DisplayOrientation.Landscape)
{
// if (this.Content.GetType() is not typeof(HomePageLandscape))
// {
this.Content = homePageLandscapeContentView;
// }
}
else if (e.DisplayInfo.Orientation == DisplayOrientation.Portrait)
{
// if (this.Content.GetType() is not typeof(HomePagePortrait))
// {
this.Content = homePagePortraitContentView;
// }
}
else
{
//Whatever you would like to do if the orientation is unknown.
}
}
}
The HomePageOrientationViewLoader.xaml file:
<?xml version="1.0" encoding="utf-8" ?>
<ContentView xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="ScoreKeepersBoard.ContentViews.HomePageOrientationViewLoader">
<VerticalStackLayout>
<Label
Text="Welcome to .NET MAUI!"
VerticalOptions="Center"
HorizontalOptions="Center" />
</VerticalStackLayout>
</ContentView>
Here is the HomePagePortrait.xaml.cs file:
namespace ScoreKeepersBoard.ContentViews;
public partial class HomePagePortrait : ContentView
{
public HomePagePortrait()
{
InitializeComponent();
}
}
Here is the HomePagePortrait.xaml file:
<?xml version="1.0" encoding="utf-8" ?>
<ContentView xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="ScoreKeepersBoard.ContentViews.HomePagePortrait">
<VerticalStackLayout>
<Label
Text="Welcome to .NET MAUI portrait"
VerticalOptions="Center"
HorizontalOptions="Center" />
</VerticalStackLayout>
</ContentView>
Here is the HomePageLandscape.xaml.cs file:
namespace ScoreKeepersBoard.ContentViews;
public partial class HomePageLandscape : ContentView
{
public HomePageLandscape()
{
InitializeComponent();
}
}
Here is the HomePageLandscape.xaml file:
<?xml version="1.0" encoding="utf-8" ?>
<ContentView xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="ScoreKeepersBoard.ContentViews.HomePageLandscape">
<VerticalStackLayout>
<Label
Text="Welcome to .NET MAUI landscape"
VerticalOptions="Center"
HorizontalOptions="Center" />
</VerticalStackLayout>
</ContentView>
My project had an initial home Content Page called HomePage. We are loading the HomePageOrientationViewLoader ContentView into the xaml of HomePage Content Page as a custom control. Note that I had to define the namespace that the ContentViews were located in and use that when defining the control in the xaml file:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:controls="clr-namespace:ScoreKeepersBoard.ContentViews"
x:Class="ScoreKeepersBoard.Views.HomePage"
Title="HomePage">
<VerticalStackLayout>
<Label
Text="Welcome to .NET MAUI Home Page Content Page"
VerticalOptions="Center"
HorizontalOptions="Center" />
<controls:HomePageOrientationViewLoader></controls:HomePageOrientationViewLoader>
</VerticalStackLayout>
</ContentPage>
Here is the code behind for the home page
namespace ScoreKeepersBoard.Views;
public partial class HomePage : ContentPage
{
public HomePage(HomeViewModel homeViewModel)
{
InitializeComponent();
}
}
and when the project runs on my iphone simulator in portrait mode:
You will see the second label shown says "Welcome to .NET MAUI portrait" which is the view from the portrait content view and when I switch to landscape:
You will see the second label shown says "Welcome to .NET MAUI landscape" which is the view from the landscape content view.
ISSUES
This works on my iPhone simulator but when I switch to my Android pixel 5 simulator and toggle my switch phone orientation it doesn't work and putting in line breaks the code defined in HomePageOrientationViewLoader is not triggered. NEW NOTE: I tried this on a physical Android phone and it is working so it must have just been the emulator.
I will need to use this for a non trivial example that has a view model that will be holding data on a sports game score, timing, etc. I guess I will just need to inject a singleton of the view model into each and they will just share and if the orientation switches the other Content View will load and the view model will bind to the appropriate controls?
The initial suggested code by FreakyAli had this check:
if (e.DisplayInfo.Orientation == DisplayOrientation.Landscape)
{
if (this.Content.GetType() is not typeof(HomePageLandscape))
{
this.Content = homePageLandscapeContentView;
}
}
but the part "typeof(HomePageLandscape) gives me an error and says a constant is expected.
Other than that the different views for different orientations is working and I thank FreakyAli mightily! I am sure I will figure out why the Android emulator is not triggering the orientation switch code, but suggestions would be awesome.

Ideally this is how i would handle such a scenario:
In my constructor, I would get the DisplayInfoChanged event which notifies me if this info changes and i would also assign my current ContentView based on the current Orientation:
DeviceDisplay.Current.MainDisplayInfoChanged += Current_MainDisplayInfoChanged;
this.Content = DeviceDisplay.Current.MainDisplayInfo.Orientation == DisplayOrientation.Portrait ? potraitView : landscapeView;
Here PortraitView is a ContentView that is the View I would display when my device is in Portrait and Vice Versa.
And then handle the runtime change of the orientation as follows:
private void Current_MainDisplayInfoChanged(object sender, DisplayInfoChangedEventArgs e)
{
if(e.DisplayInfo.Orientation==DisplayOrientation.Landscape)
{
if(this.Content.GetType() is not typeof(LandscapeView))
{
this.Content = landscapeView;
}
}
else if (e.DisplayInfo.Orientation == DisplayOrientation.Portrait)
{
if (this.Content.GetType() is not typeof(PortraitView))
{
this.Content = portraitView;
}
}
else
{
//Whatever you would like to do if the orientation is unknown.
}
}
Hope this helps you!

The proper way to do this is through ContentViews where you have 2 ContentViews, one for portrait and one for landscape. You have another ContentView that is used to choose to load in either landscape or portrait depending on the orientation.
I created a tutorial that puts all of the pieces together:
https://codeshadowhand.com/net-maui-different-layouts-for-portrait-vs-landscape/
Thanks a million to FreakyAli for pointing me in the right direction!!!

Related

Get native iOS system tab bar icons for TabbedPage on Xamarin.Forms

I am new to Xamarin.Forms and XAML. I am trying to get tab icons to display for ONLY IOS for the my different pages in my TabbedPage. I did a bit of search and I have come to know that UIKit has a reference to system icons available on IOS at UITabBarSystem. How can I make use of the elements in that enum without having to get those icons from the internet? The TabbedPage is the root with children pages that are ContentPages and ListView pages. So as you will see from the attached sample, I would like the "IconImageSource" property for FavouritesPage to get the image from the iOS UIKit. Is that possible?
<?xml version="1.0" encoding="utf-8" ?>
<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:views="clr-namespace:PhoneApp.Views"
x:Class="PhoneApp.Views.MainPage">
<TabbedPage.Title>
</TabbedPage.Title>
<TabbedPage.Children>
<views:FavouritesPage Title="Favourites" IconImageSource=""/>
<views:RecentsPage Title="Recents"/>
<views:ContactsPage Title="Contacts"/>
<views:KeypadPage Title="Keypad"/>
<views:VoicemailPage Title="Voicemail"/>
</TabbedPage.Children>
</TabbedPage>
I think I found the right solution for you. If you want to use native Api's on Xamarin controls, you can use custom renderer for them which are great! Here is the renderer for the TabedPage:
[assembly: ExportRenderer(typeof(MainPage), typeof(MyTabbedPageRenderer))]
namespace TestApp.iOS
{
public class MyTabbedPageRenderer : TabbedRenderer
{
public override void ViewWillAppear(bool animated)
{
base.ViewWillAppear(animated);
if (TabBar?.Items == null) return;
//Setting the Icons
TabBar.Items[0].Image = GetTabIcon(UITabBarSystemItem.Search);
TabBar.Items[1].Image = GetTabIcon(UITabBarSystemItem.Downloads);
TabBar.Items[2].Image = GetTabIcon(UITabBarSystemItem.Bookmarks);
}
private UIImage GetTabIcon(UITabBarSystemItem systemItem)
{
//Convert UITabBarItem to UIImage
UITabBarItem item = new UITabBarItem(systemItem, 0);
return UIImage.FromImage(item.SelectedImage.CGImage, item.SelectedImage.CurrentScale, item.SelectedImage.Orientation);
}
}
}
I created a sample for you, which you can find here. If you have any questions, please ask!
Regards

Connecting Xamarin Form tabbed pages to XAML

I am fairly new to all of this and am currently attempting to get the height of the tabs in the Xamarin tabbed page form. The only solution I found to this is to write a custom renderer, and that is what I'm having a hard time with.
After a couple days of struggling I managed to get to this spot (hopefully on the right track), however I just cannot understand how to connect the XAML to my custom tabbed page. This is what I have so far.
GameTab.xaml
<?xml version="1.0" encoding="utf-8" ?>
<TabbedPage
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Diplomacy.Views.GameTab"
xmlns:pages="clr-namespace:Diplomacy.Views"
xmlns:custom="clr-namespace:Diplomacy.CustomRenderers">
<!--Pages can be added as references or inline-->
<TabbedPage.Children>
<pages:TabbedMap Title="Map" Icon="tank.png"/>
<pages:TabbedChat Title="Chat" Icon="chat.png"/>
</TabbedPage.Children>
</TabbedPage>
GameTab.xaml.cs
namespace Diplomacy.Views
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class GameTab : Xamarin.Forms.TabbedPage
{
SelectionGamesViewModel viewModel;
public GameTab(SelectionGamesViewModel viewModel)
{
InitializeComponent();
// Disables switching between tabs with the swipe gesture
On<Xamarin.Forms.PlatformConfiguration.Android>().DisableSwipePaging();
// Sets the tab at the bottom in android phones
On<Xamarin.Forms.PlatformConfiguration.Android>().SetToolbarPlacement(ToolbarPlacement.Bottom);
BindingContext = this.viewModel = viewModel;
}
}
MyCustomRenderer.cs
namespace Diplomacy.CustomRenderers
{
public class CustomTabbedPage : Xamarin.Forms.TabbedPage
{
}
}
At this point my next step is to use the CustomTabbedPage (correct me if I'm wrong from here on out).
With this line: xmlns:custom="clr-namespace:Diplomacy.CustomRenderers"
I should be able to wedge myself into the Xamarin Tabbed Page form with my custom render, which currently does nothing.
The way that I believe this is done is by changing TabbedPage to CustomTabbedPage like shown below
<?xml version="1.0" encoding="utf-8" ?>
<custom:CustomTabbedPage
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Diplomacy.Views.GameTab"
xmlns:pages="clr-namespace:Diplomacy.Views"
xmlns:custom="clr-namespace:Diplomacy.CustomRenderers">
<!--Pages can be added as references or inline-->
.
. // Same stuff goes here
.
</custom:CustomTabbedPage>
However when I do that, I get all sorts of errors in GameTab.xaml.cs and 1 error in the navigation page trying to push GameTab (the 2nd error)
I've been struggling probably for weeks now, I really need some help on how to set up this custom render. I get the theory of what it does and what is it's purpose, however I don't fully understand how the compiler handles it all, and how to link it all together. Please and thank you. Sorry for the long question, I just wanted to be thorough.
EDIT:
This is the Android custom renderer code that lives in Diplomacy.Android
[assembly: ExportRenderer(typeof(CustomTabbedPage), typeof(MyTabbedPage))]
namespace Diplomacy.Droid.CustomRenderer
{
public class MyTabbedPage : TabbedRenderer
{
public MyTabbedPage(Context context) : base(context)
{
}
}
}
All the errors that you get are for one and one reason alone that the other part of your partial class i.e. GameTab.xaml.cs files GameTab class is not inheriting from your CustomTabbedPage but your Xamarin.Forms.TabbedPage
All you have to do is something like this in your GameTab.xaml.cs
public partial class GameTab : Diplomacy.CustomRenderers.CustomTabbedPage

Xamarin TabbedPages MVVM Binding

How to bind tabbed page with different view models?
To make it clearer I have this tabbed page:
<TabbedPage.Children>
<tabPages:Page1/>
<tabPages:Page2/>
<tabPages:Page3/>
</TabbedPage.Children>
These 3 pages have different view models. However, the problem is the view models of each pages won't bind. Is there a specific way in order to do this?
To test if my view models for each pages works, I inlined the code in tabbed page:
e.g.
<TabbedPage.Children>
<ContentPage Title="Test">
<Label Text="{Binding TestBind}"/>
</ContentPage>
</TabbedPage.Children>
And for bind it to the view model of the tabbed page (parent) - this method works. However, if I do it separately, the view models wouldn't bind.
E.g.
public class Page1ViewModel : BaseViewModel
{
public Page1ViewModel()
{
TestBind = "Test";
}
private string _TestBind;
public string TestBind
{
get { return _TestBind; }
set { SetProperty(ref _TestBind, value); }
}
}
Using it this way, it wouldn't bind
I've made it worked, so this is what I did:
<TabbedPage.Children>
<views:ChildPage1>
<views:ChildPage1.BindingContext>
<viewModels:ChildPage1ViewModel/>
</views:ChildPage1.BindingContext>
</views:ChildPage1>
<views:ChildPage2>
<views:ChildPage2.BindingContext>
<viewModels:ChildPage2ViewModel/>
</views:ChildPage2.BindingContext>
</views:ChildPage2>
</TabbedPage.Children>
I used binding context property of the element to set it.
Why not just set the BindingContext of each TabPage to each ViewModel:
<TabbedPage.Children>
<tabPages:Page1 BindingContext="{Binding viewModel1}" />
<tabPages:Page2 BindingContext="{Binding viewModel2}" />
<tabPages:Page3 BindingContext="{Binding viewModel3}"/>
</TabbedPage.Children>
Those ViewModels would have to exist as properties in the parent VM.

Xamarin.Forms adding children to TabbedPage within OnBindingContextChanged

I'm trying to implement a TabbedPage using MvvmCross for my navigation. The problem is MvvmCross uses ViewModel first navigation and this doesn't seem to play well with the general approach one might take to add children to a TabbedPage; because I do not have access to a non-null ViewModel during page construction, but I do have access to it within OnBindingContextChanged.
Here's what I have so far...
DashboardPage.xaml:
<?xml version="1.0" encoding="UTF-8"?>
<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="DashboardPage"
xmlns:local="clr-namespace:CoreUI;assembly=CoreUI"
SelectedItem="{Binding CurrentSection, Mode=TwoWay}">
</TabbedPage>
DashboardPage.xaml.cs:
public partial class DashboardPage : TabbedPage
{
public DashboardPage()
{
InitializeComponent();
}
protected override void OnBindingContextChanged()
{
var vm = (BindingContext as DashboardViewModel);
if (vm == null)
{
return;
}
ObservableCollection<MainMenuSection> sections = vm.MenuSections;
foreach (var section in sections)
{
MainMenuViewModel main_menu_vm = new MainMenuViewModel
{
Section = section
};
// Question 2:
// Going against the MvvmCross grain here by referring to other pages from within a page, as opposed to doing everything from a ViewModel. How do I get around this?
Children.Add(new MainMenuPage(main_menu_vm));
}
}
}
MainMenuPage.xaml (pay attention to the comments here):
<?xml version="1.0" encoding="UTF-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="MainMenuPage"
xmlns:local="clr-namespace:CoreUI;assembly=CoreUI"
Title="{Binding Title}" > <!-- The tabs that are displayed on Dashboard have the correct labels, so Binding appears to be working here. -->
<ContentPage.Content>
<StackLayout x:Name="Body" IsVisible="false">
<Label Text="{Binding Title}"/> <!-- Label doesn't get displayed, but does get displayed if Text is bound to something static, so Binding not quite working here. -->
</StackLayout>
</ContentPage.Content>
</ContentPage>
MainMenuPage.xaml.cs:
public partial class MainMenuPage : ContentPage
{
public MainMenuPage(MainMenuViewModel vm)
{
InitializeComponent();
BindingContext = vm;
}
protected override void OnBindingContextChanged()
{
Body.IsVisible = true;
}
}
The above MainMenuPage is a simplified version of what I have to illustrate my point, which is that I get a blank page for each tab within DashboardPage.
Question 1: Why are the tab pages blank?
Question 2: Refer to comment in DashboardPage.xaml.cs.
Why would you do this whole thing yourself? As you can see in the samples (https://github.com/MvvmCross/MvvmCross/tree/develop/TestProjects/Playground/Playground.Forms.UI/Pages) you can just decorate your view with a MvxTabbePagePresentation attribute and MvvmCross will handle the rest for you!
I would also advice to use the Mvx type pages to take advantage of lots of features.

How to Keep Button Upright When Device Position Changes

I'd like to be able to allow a button that I have in my application to always remain looking like it is in the upright position, even when the device is rotated clockwise or counterclockwise. The standard app bar kind of does this with adjusting the application bar icons according to whether the device is in portrait or landscape mode, so I'd like to do something similar with a button on my page. How might I do something like this? Any recommendations into the methods? I'd like to either stick with something like what the app bar already does, or always rotate the button so it remains upright as the device rotates.
<Button x:Name="CameraButton" Grid.Row="1" Grid.Column="0" Margin="-48,0,0,-12"
Click="CameraButton_Click">
<Button.Content>
<Image Source="/Assets/Camera_Button1.png"/>
</Button.Content>
</Button>
If you do not care the rotate animation auto played by system, you can easily achieve by providing 3 different icons(Portrait, LandscapeLeft, LandscapeRight).
In Xaml, you first add your ApplicationBarIconButton into the page Resource, and change its IconUri later when OrientationChanged is fired. Hope it helps.
The project code can be downloaded here:
http://hdtp.synology.me/ApplicationBarIconDirection.zip
xaml code:
<phone:PhoneApplicationPage
x:Class="ApplicationBarIconDirection.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="768"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="PortraitOrLandscape" Orientation="Portrait"
shell:SystemTray.IsVisible="True"
OrientationChanged="PhoneApplicationPage_OrientationChanged">
<phone:PhoneApplicationPage.Resources>
<shell:ApplicationBarIconButton x:Key="icon_arrow" IconUri="/Assets/up.png" Text="FixedUp"/>
</phone:PhoneApplicationPage.Resources>
<!--LayoutRoot is the root grid where all page content is placed-->
<Grid x:Name="LayoutRoot" Background="Transparent">
</Grid>
<phone:PhoneApplicationPage.ApplicationBar>
<shell:ApplicationBar IsVisible="True" IsMenuEnabled="True">
</shell:ApplicationBar>
</phone:PhoneApplicationPage.ApplicationBar>
</phone:PhoneApplicationPage>
xaml.cs code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Shell;
namespace ApplicationBarIconDirection
{
public partial class MainPage : PhoneApplicationPage
{
// Constructor
public MainPage()
{
InitializeComponent();
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
this.ApplicationBar.Buttons.Add(this.Resources["icon_arrow"] as ApplicationBarIconButton);
}
private void PhoneApplicationPage_OrientationChanged(object sender, OrientationChangedEventArgs e)
{
if (e.Orientation == PageOrientation.LandscapeLeft)
{
(this.Resources["icon_arrow"] as ApplicationBarIconButton).IconUri = new Uri("/Assets/left.png", UriKind.Relative);
}
else if (e.Orientation == PageOrientation.LandscapeRight)
{
(this.Resources["icon_arrow"] as ApplicationBarIconButton).IconUri = new Uri("/Assets/right.png", UriKind.Relative);
}
else
{
(this.Resources["icon_arrow"] as ApplicationBarIconButton).IconUri = new Uri("/Assets/up.png", UriKind.Relative);
}
}
}
}
Application Bar has a property named SupportedOrientation which makes it change its orientation every time the orientation of the phone changes (see this ). But, If we look at button then we see that there is neither such property named SupportedOrientation nor any other property functioning analogous to that of SupportedOrientation for applicationbar. I would hence recommend you to make your own logic according to the changes in the phones orientation.
sample logic to change orientations-
logic to rotate a button
CompositeTransform ct=new CompositeTransform (){Rotation=90};
button.Rendertransform=ct;
Apply this on orientation changes like this
private void PhoneApplicationPage_OrientationChanged(object sender, OrientationChangedEventArgs e)
{
if (e.Orientation == PageOrientation.LandscapeLeft)
{
//apply rotation with some angle say 90
}
else if (e.Orientation == PageOrientation.LandscapeRight)
{
//apply rotation 180
}
else if(e.Orientation == PageOrientation.PortraitUp)
{
//apply rotation 270
}
else if(e.Orientation == PageOrientation.PortraitDown)
{
//apply rotation 360
}
}
And for smoothness like that in applicationbar buttons you would have to make your hands dirty with the storyboards and animations using expression blend