Ejemplo n.º 1
0
        public App()
        {
            // GlobalVariables.Add(typeof(IMainViewModel), () => new MainViewModel());

            InitializeComponent();

            var firstAccessedMainViewModel  = AppContainer.Container.Resolve <IMainViewModel>();
            var secondAccessedMainViewModel = AppContainer.Container.Resolve <IMainViewModel>();
            var areEqual = ReferenceEquals(firstAccessedMainViewModel, secondAccessedMainViewModel);

            // Injects the second view model because it was added to the container last.
            var whoKnowsWhatThisIs = AppContainer.Container.Resolve <ClassWithConstructors>();

            // MainPage = new MainPage() { BindingContext = GlobalVariables[typeof(IMainViewModel)] };
            var mainPage = new MainPage {
                BindingContext = AppContainer.Container.Resolve <IMainViewModel>()
            };

            MainPage = mainPage;

            Device.BeginInvokeOnMainThread
            (
                async() =>
            {
                await Task.Delay(5000);
                var secondPage = new SecondPage();
                MainPage       = secondPage;
                await Task.Delay(5000);
                MainPage   = mainPage;
                secondPage = null;
                GC.Collect();
            });
        }
Ejemplo n.º 2
0
        public App()
        {
            // GlobalVariables.Add(typeof(IMainViewModel), () => new MainViewModel());

            InitializeComponent();

            var firstAccessedMainViewModel  = AppContainer.Container.Resolve <IMainViewModel>();
            var secondAccessedMainViewModel = AppContainer.Container.Resolve <IMainViewModel>();
            var areEqual = ReferenceEquals(firstAccessedMainViewModel, secondAccessedMainViewModel);

            // Injects the second view model because it was added to the container last.
            var whoKnowsWhatThisIs = AppContainer.Container.Resolve <ClassWithConstructors>();

            // MainPage = new MainPage() { BindingContext = GlobalVariables[typeof(IMainViewModel)] };
            var mainPage = new MainPage {
                BindingContext = AppContainer.Container.Resolve <IMainViewModel>()
            };

            MainPage = mainPage;

            Device.BeginInvokeOnMainThread
            (
                async() =>
            {
                await Task.Delay(5000);
                var secondPage = new SecondPage();
                Debug.WriteLine("About to assign the main page to the second page.");
                MainPage = secondPage;
                Debug.WriteLine("Finished assigning the main page to the second page.");

#if !PREVENT_PAGE_CHANGE
                await Task.Delay(5000);
                Debug.WriteLine("About to assign the main page to the original main page.");
                MainPage = mainPage;
                Debug.WriteLine("Finished assigning the main page to the original main page.");
#endif

                // Force clean-up
                secondPage.Stop();
                secondPage = null;
                GC.Collect();
            });
        }