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); } }
Task ILoadScreen.LoadScreenAsync(object parentViewModel, IUIView parentViewScreen, object childViewModel, IUIView childViewScreen) { if (childViewModel is IScreen childScreen && childViewScreen is UserControl childui && parentViewScreen is UIElement parentui) { var item = childui.Content; GamePackageViewModelBinder.Bind(childViewModel, childui, (DependencyObject)item); GamePackageViewModelBinder.HookParentContainers(parentViewModel, parentui, childScreen, childViewScreen); } return Task.CompletedTask; }
async Task IHandleAsync<IUIView>.HandleAsync(IUIView message) { await Task.CompletedTask; //await Task.Delay(50); if (!(message is UserControl control)) { return; } //GamePackageViewModelBinder.StepThrough = false; //if (!(message )) //childViewScreen is UserControl childui //var item = (DependencyObject) control.Content; //VisualTreeHelper.GetChildrenCount(depObj) //var count = VisualTreeHelper.GetChildrenCount(item); //well see how iffy this is. DependencyObject nextItem; if (control.Content is ContentControl content) { nextItem = (DependencyObject)content.Content; } else if (control.Content is Grid grid) { //int count = VisualTreeHelper.GetChildrenCount(grid); //var xx = control.FindName("ChangeFlag"); //GamePackageViewModelBinder.StepThrough = true; nextItem = grid; //VisualTreeHelper.GetChildrenCount(depObj); i++) //throw new NotImplementedException(); } else { nextItem = (DependencyObject)control.Content; } //ContentControl content = (ContentControl)control.Content; //var //count = VisualTreeHelper.GetChildrenCount(nextItem); //needs more complex when its rebinding. GamePackageViewModelBinder.Bind(message.DataContext, control, nextItem); //this can rescan the bindings. hopefully no problem. GamePackageViewModelBinder.ManuelElements.Clear(); //hopefully won't hurt anything if i clear out. }
Task ILoadScreen.LoadScreenAsync(object parentViewModel, IUIView parentViewScreen, object childViewModel, IUIView childViewScreen) { //if (GamePackageViewModelBinder.StopRun) //{ // return Task.CompletedTask; //} if (childViewModel is IScreen childScreen && childViewScreen is ContentView childui && parentViewScreen is VisualElement parentui) { var item = childui.Content; GamePackageViewModelBinder.Bind(childViewModel, childui, item); GamePackageViewModelBinder.HookParentContainers(parentViewModel, parentui, childScreen, childViewScreen); } return(Task.CompletedTask); }
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); } }
async Task IHandleAsync <IUIView> .HandleAsync(IUIView message) { await Task.CompletedTask; //await Task.Delay(50); if (!(message is View control)) { return; } //DependencyObject nextItem; //if (control.Content is ContentControl content) //{ // nextItem = (DependencyObject)content.Content; //} //else if (control.Content is Grid grid) //{ // //int count = VisualTreeHelper.GetChildrenCount(grid); // //var xx = control.FindName("ChangeFlag"); // //GamePackageViewModelBinder.StepThrough = true; // nextItem = grid; // //VisualTreeHelper.GetChildrenCount(depObj); i++) // //throw new NotImplementedException(); //} //else //{ // nextItem = (DependencyObject)control.Content; //} //ContentControl content = (ContentControl)control.Content; //var //count = VisualTreeHelper.GetChildrenCount(nextItem); //needs more complex when its rebinding. //hopefully no need for the content. could be very iffy. lots of rethinking could be required. including the manuellist. GamePackageViewModelBinder.Bind(message.DataContext, control); //this can rescan the bindings. hopefully no problem. //GamePackageViewModelBinder.ManuelElements.Clear(); //hopefully won't hurt anything if i clear out. }