What’s new in Xamarin.Forms 1.3 : Inherited App Class
With the new release of Xamarin.Forms 1.3 version, the App Class has its new Avatar.
The Older version of App Class was just a class with static methods.
Unlike the older version, the new version is an inherited class from the Xamarin.Forms.Application class.
Summary of improvements
Addition of new life cycle events :
We can handle separate events during different phases of app interaction life cycle.
- onStart :- Allows us to handle the app start up. We can write code here to get executed during on app start up.
- onSleep :- We can write code here to get executed while app in entering into the sleep/minimize mode.
- onResume :- Code can be executed after the app regains the focus.
Self static object :
Application class uses a static instance of its own, which is named as Current. It can be accessed through out the application.
1 2 3 |
Application.Current |
MainPage attribute :
MainPage is an attribute of the Application Class of type ContentPage. As the name suggest, we can assign the root page of the application to this attribute.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
// The root page of your application MainPage = new ContentPage { Content = new StackLayout { VerticalOptions = LayoutOptions.Center, Children = { new Label { XAlign = TextAlignment.Center, Text = "Welcome to Xamarin Forms!" } } } }; |
Properties :
Not to be confused, this is an attribute of the Application Class. It contains the Dictionary object. We can read/write application level global variables to it for further use in a Key and Value pair format.
1 2 3 |
Application.Current.Properties.Add(new KeyValuePair<string, object>("AppOwner", "Nirmal")); |
Resources :
Application Class Resources attribute can store the resources for application use. This attribute is of type ResourceDictionary.We can add Implicit Styles (in XAML) and Key Value pair strings to it.
1 2 3 |
Application.Current.Resources.Add("AppCaption", "My App"); |
Happy coding š
Categories: Android, Cross Platform Mobile App, iOS, Visual Studio, Windows Phone, Xamarin