コード例 #1
0
        public App(IAuthenticationHandler authenticationHandler = null)
        {
            InitializeComponent();
            FlowListView.Init();

            // OOP Demo Comment

            // Setup IoC Container for Dependeny Injection
            ServiceLocator.SetLocatorProvider(() => SimpleIoc.Default);
            SimpleIoc.Default.Reset();

            // Register Dependencies
            if (authenticationHandler != null)
            {
                SimpleIoc.Default.Register <IAuthenticationHandler>(() => authenticationHandler);
            }
            SimpleIoc.Default.Register <IAppEnvironment, AppEnvironment>();
            SimpleIoc.Default.Register <IPhotoCroppingService>(() => DependencyService.Get <IPhotoCroppingService>());
            SimpleIoc.Default.Register <IPhotoService, ServiceClient>();
            SimpleIoc.Default.Register <IDialogService, FormsDialogService>();
            SimpleIoc.Default.Register <IConnectivityService, FormsConnectivityService>();
            SimpleIoc.Default.Register <ISettingsService, FormsSettingsService>();

            SimpleIoc.Default.Register <CategoriesViewModel>();
            SimpleIoc.Default.Register <PhotoDetailsViewModel>();
            SimpleIoc.Default.Register <StreamPageViewModel>();
            SimpleIoc.Default.Register <CameraViewModel>();
            SimpleIoc.Default.Register <ProfileViewModel>();
            SimpleIoc.Default.Register <SettingsViewModel>();

            // Setup App Container
            var navigationPage = new Xamarin.Forms.NavigationPage();

            navigationPage.BarBackgroundColor = (Color)Resources["AccentColor"];
            navigationPage.BarTextColor       = Color.White;

            // Register Navigation Service
            var navigationService = new FormsNavigationService(navigationPage);

            navigationService.Configure(ViewNames.PhotoDetailsPage, typeof(PhotoDetailsPage));
            navigationService.Configure(ViewNames.StreamPage, typeof(StreamPage));
            navigationService.Configure(ViewNames.SettingsPage, typeof(SettingsPage));
            SimpleIoc.Default.Register <INavigationService>(() => navigationService);

            // Setup App Shell
            AppShell = new AppShell();
            AppShell.Children.Add(new CategoriesPage());   // Home
            AppShell.Children.Add(new CameraPage());       // Upload
            AppShell.Children.Add(new LeaderboardsPage()); // Leaderboards
            AppShell.Children.Add(new ProfilePage());      // My profile
            AppShell.On <Android>().DisableSwipePaging();

            navigationPage.PushAsync(AppShell);
            MainPage = navigationPage;
        }