コード例 #1
0
        protected async Task ShowWindowAsync(IUIView view, object rootModel)
        {
            Window? window = null;
            if (view is Window window1)
            {
                window = window1;
                BeforeLoadingWindow(window);
                Application!.MainWindow = window;
                //do work with the titles.
                if (view is IUISetting ui)
                {
                    OurContainer!.RegisterSingleton(ui);
                }
                window.Show();

            }
            if (rootModel is IScreen screen)
                await screen.ActivateAsync(view);
            //i think that after activate will it set the display bindings.  that way we have every chance possible of doing the bindings.
            if (window != null)
            {
                if (string.IsNullOrEmpty(window.Title) && rootModel is IHaveDisplayName && !ViewModelBinder.HasBinding(window, Window.TitleProperty))
                {
                    //if you don't implement the idisplay, then this will not run.  so you have flexibility of what to pass in for view model.
                    //this allows you to use as little or as much as you want for the windows.

                    var binding = new Binding("DisplayName") { Mode = BindingMode.OneWay }; //i like this way better.
                    window.SetBinding(Window.TitleProperty, binding);
                }
                //ViewModelBinder.Bind(childViewModel, childui, (DependencyObject)item);
                GamePackageViewModelBinder.Bind(rootModel, window, (DependencyObject)window.Content);
            }
        }
コード例 #2
0
        protected async Task ShowPageAsync(IUIView view, object rootModel)
        {
            ContentPage?page = null;

            if (view is ContentPage window1)
            {
                page = window1;


                //await Application!.MainPage.Navigation.PushAsync(page);


                if (_mode == EnumGamePackageMode.Debug)
                {
                    Application !.MainPage = page; //hopefully its this simple (?)
                }
                else
                {
                    await Application !.MainPage.Navigation.PushAsync(page);
                }
                BeforeLoadingPage(page);
                //risk not even register the view now since it should already be done elsewhere.
                //OurContainer!.RegisterSingleton(view); //risked this way.  hopefully i don't regret this.
                _mainPage = page;
            }
            if (rootModel is IScreen screen)
            {
                await screen.ActivateAsync(view);
            }
            //i think that after activate will it set the display bindings.  that way we have every chance possible of doing the bindings.
            if (page != null)
            {
                if (string.IsNullOrEmpty(page.Title) && rootModel is IHaveDisplayName && !ViewModelBinder.HasBinding(page, Page.TitleProperty))
                {
                    //if you don't implement the idisplay, then this will not run.  so you have flexibility of what to pass in for view model.
                    //this allows you to use as little or as much as you want for the windows.

                    var binding = new Binding("DisplayName")
                    {
                        Mode = BindingMode.OneWay
                    };                                                                      //i like this way better.
                    page.SetBinding(Page.TitleProperty, binding);
                }
                GamePackageViewModelBinder.Bind(rootModel, page);
            }
        }