Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* MAINVIEW.CS */
- public class MainView : ContentPage
- {
- public MainView()
- {
- // Label Header
- Label header = new Label();
- header.Text = "Main Menu";
- header.Font = Font.BoldSystemFontOfSize (40);
- header.HorizontalOptions = LayoutOptions.Center;
- // Declaring Buttons
- Button btnGetAllUsers = new Button ();
- btnGetAllUsers.Text = "Get All Users";
- btnGetAllUsers.Font = Font.BoldSystemFontOfSize (NamedSize.Large);
- btnGetAllUsers.BorderWidth = 1;
- Button btnCreateUser = new Button();
- btnCreateUser.Text = "Create a User";
- btnCreateUser.Font = Font.BoldSystemFontOfSize(NamedSize.Large);
- btnCreateUser.BorderWidth = 1;
- // Button Click Events
- // I AM PUSHING THE SAME VIEW CLASS ON THE "BUTTON CLICK EVENT" JUST TO ILUSTRATE THE EXCEPTION. THE SAME ERROR IS RAISED
- // BY DOING THIS.
- btnGetAllUsers.Clicked += async (sender, args) => await Navigation.PushAsync (ViewsHandler.GetMainPage());
- // Building the Page
- this.Content = new StackLayout
- {
- Children =
- {
- header,
- new StackLayout
- {
- HorizontalOptions = LayoutOptions.Center,
- Children = { btnGetAllUsers, btnCreateUser }
- }
- }
- };
- }
- }
- /* VIEWS HANDLER.CS - JUST A WRAPPER TO PROVIDE NEW INSTANCES OF THE VIEWS */
- public class ViewsHandler
- {
- public static Page GetMainPage()
- {
- return new NavigationPage (new MainView());
- }
- public static Page GetUsersListPage()
- {
- return new NavigationPage (new UsersListView ());
- }
- }
- /* ANDROID INITIALIZATION CODE */
- public class MainActivity : AndroidActivity
- {
- protected override void OnCreate(Bundle bundle)
- {
- base.OnCreate(bundle);
- // Initializing Xamarin Form
- Xamarin.Forms.Forms.Init (this, bundle);
- // Setting main page
- SetPage (ViewsHandler.GetMainPage());
- }
- }
- /* WINDOWS PHONE INITIALIZATION CODE */
- public MainPage()
- {
- InitializeComponent();
- // Sample code to localize the ApplicationBar
- //BuildLocalizedApplicationBar();
- Forms.Init ();
- Content = TrumpetMobile.Views.ViewsHandler.GetMainPage().ConvertPageToUIElement (this);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement