void SetupCM() { var original = ViewLocator.LocateForModel; ViewLocator.LocateForModel = (o, dependencyObject, arg3) => { var v = original(o, dependencyObject, arg3); // TODO: Lacks CM's Context/target support if ((v == null) || v is TextBlock) { var rxv = (UIElement)ReactiveUI.ViewLocator.Current.ResolveView(o); if (rxv != null) { v = rxv; } } var vFor = v as IViewFor; if (vFor != null) { vFor.ViewModel = o; } return(v); }; //ViewLocator.AddNamespaceMapping("withSIX.Core.Presentation.Wpf.Views", "withSIX.Core.Presentation.Wpf.Views"); ViewLocator.AddNamespaceMapping("withSIX.Core.Applications.MVVM.ViewModels.Popups", "withSIX.Core.Presentation.Wpf.Views.Popups"); ViewLocator.AddNamespaceMapping("withSIX.Core.Applications.MVVM.ViewModels.Dialogs", "withSIX.Core.Presentation.Wpf.Views.Dialogs"); ViewLocator.AddNamespaceMapping("withSIX.Core.Applications.MVVM.ViewModels", "withSIX.Core.Presentation.Wpf.Views"); }
protected override void SetupViewNamespaces() { base.SetupViewNamespaces(); var concepts = new[] { "Connect", "Games", "Games.Library" }; var types = new[] { "Overlays", "Popups", "Dialogs" }; var nsRootSource = "withSIX.Play.Applications.ViewModels"; var nsRootTarget = "withSIX.Play.Presentation.Wpf.Views"; // Setup root ViewLocator.AddNamespaceMapping(nsRootSource, nsRootTarget); foreach (var type in types) { ViewLocator.AddNamespaceMapping(nsRootSource + "." + type, nsRootTarget + "." + type); } // Setup concepts foreach (var concept in concepts) { var nsSource = nsRootSource + "." + concept; var nsTarget = nsRootTarget + "." + concept; ViewLocator.AddNamespaceMapping(nsSource, nsTarget); foreach (var type in types) { ViewLocator.AddNamespaceMapping(nsSource + "." + type, nsTarget + "." + type); } } }
public override void ShowPopup(object rootModel, object context = null, IDictionary <string, object> settings = null) { var popup = CreatePopup(rootModel, settings); var view = ViewLocator.LocateForModel(rootModel, popup, context); SetupRxPopup(rootModel, view, popup); popup.Child = view; popup.SetValue(View.IsGeneratedProperty, true); SetupCaliburn(rootModel, popup, view); popup.IsOpen = true; popup.CaptureMouse(); }
private RadWindow PrepareRadWindow(object rootModel, object context, IDictionary <string, object> settings) { var view = EnsureWindow(rootModel, ViewLocator.LocateForModel(rootModel, null, context)); ViewModelBinder.Bind(rootModel, view, context); var haveDisplayName = rootModel as IHaveDisplayName; if (haveDisplayName != null && !ConventionManager.HasBinding(view, RadWindow.HeaderProperty)) { var binding = new Binding("DisplayName") { Mode = BindingMode.TwoWay }; view.SetBinding(RadWindow.HeaderProperty, binding); } new RadWindowConductor(rootModel, view); ApplySettings(view, settings); return(view); }
/// <summary> /// Occurs after navigation /// </summary> /// <param name="sender"> The event sender. </param> /// <param name="e"> The event args. </param> protected virtual async void OnNavigated(object sender, NavigationEventArgs e) { if (e.Uri.IsAbsoluteUri || e.Content == null) { return; } ViewLocator.InitializeComponent(e.Content); var viewModel = ViewModelLocator.LocateForView(e.Content); if (viewModel == null) { return; } var page = e.Content as Page; if (page == null) { throw new ArgumentException("View '" + e.Content.GetType().FullName + "' should inherit from Page or one of its descendents."); } if (treatViewAsLoaded) { page.SetValue(View.IsLoadedProperty, true); } TryInjectParameters(viewModel, e.ExtraData); ViewModelBinder.Bind(viewModel, page, null); if (viewModel is IActivate activator) { await activator.ActivateAsync(); } GC.Collect(); }
/// <summary> /// Shows a modal dialog for the specified model. /// </summary> /// <param name="rootModel">The root model.</param> /// <param name="context">The context.</param> /// <param name="settings">The optional dialog settings.</param> public virtual void ShowDialog(object rootModel, object context = null, IDictionary <string, object> settings = null) { var view = EnsureWindow(rootModel, ViewLocator.LocateForModel(rootModel, null, context)); ViewModelBinder.Bind(rootModel, view, context); var haveDisplayName = rootModel as IHaveDisplayName; if (haveDisplayName != null && !ConventionManager.HasBinding(view, ChildWindow.TitleProperty)) { var binding = new Binding("DisplayName") { Mode = BindingMode.TwoWay }; view.SetBinding(ChildWindow.TitleProperty, binding); } ApplySettings(view, settings); new WindowConductor(rootModel, view); view.Show(); }
/// <summary> /// Creates a window. /// </summary> /// <param name="rootModel">The view model.</param> /// <param name="isDialog">Whethor or not the window is being shown as a dialog.</param> /// <param name="context">The view context.</param> /// <param name="settings">The optional popup settings.</param> /// <returns>The window.</returns> protected virtual Window CreateWindow(object rootModel, bool isDialog, object context, IDictionary <string, object> settings) { var view = EnsureWindow(rootModel, ViewLocator.LocateForModel(rootModel, null, context), isDialog); ViewModelBinder.Bind(rootModel, view, context); var haveDisplayName = rootModel as IHaveDisplayName; if (haveDisplayName != null && !ConventionManager.HasBinding(view, Window.TitleProperty)) { var binding = new Binding("DisplayName") { Mode = BindingMode.TwoWay }; view.SetBinding(Window.TitleProperty, binding); } ApplySettings(view, settings); new WindowConductor(rootModel, view); return(view); }
/// <summary> /// Shows a popup at the current mouse position. /// </summary> /// <param name="rootModel">The root model.</param> /// <param name="context">The view context.</param> /// <param name="settings">The optional popup settings.</param> public virtual async Task ShowPopupAsync(object rootModel, object context = null, IDictionary <string, object> settings = null) { var popup = CreatePopup(rootModel, settings); var view = ViewLocator.LocateForModel(rootModel, popup, context); popup.Child = view; popup.SetValue(View.IsGeneratedProperty, true); ViewModelBinder.Bind(rootModel, popup, null); Action.SetTargetWithoutContext(view, rootModel); if (rootModel is IActivate activator) { await activator.ActivateAsync(); } if (rootModel is IDeactivate deactivator) { popup.Closed += async(s, e) => await deactivator.DeactivateAsync(true); } popup.IsOpen = true; popup.CaptureMouse(); }
/// <summary> /// Binds the view model. /// </summary> /// <param name="view">The view.</param> /// <param name="viewModel">The view model.</param> protected virtual async Task BindViewModel(DependencyObject view, object viewModel = null) { ViewLocator.InitializeComponent(view); viewModel = viewModel ?? ViewModelLocator.LocateForView(view); if (viewModel == null) { return; } if (treatViewAsLoaded) { view.SetValue(View.IsLoadedProperty, true); } TryInjectParameters(viewModel, CurrentParameter); ViewModelBinder.Bind(viewModel, view, null); if (viewModel is IActivate activator) { await activator.ActivateAsync(); } }
/// <summary> /// Shows a settings flyout panel for the specified model. /// </summary> /// <param name="viewModel">The settings view model.</param> /// <param name="commandLabel">The settings command label.</param> /// <param name="viewSettings">The optional dialog settings.</param> /// <param name="independent">Show settings independent from <seealso cref="Windows.UI.ApplicationSettings.SettingsPane"/>.</param> public async void ShowSettingsFlyout(object viewModel, string commandLabel, IDictionary <string, object> viewSettings = null, bool independent = false) { var view = ViewLocator.LocateForModel(viewModel, null, null); ViewModelBinder.Bind(viewModel, view, null); viewSettings = viewSettings ?? new Dictionary <string, object>(); var settingsFlyout = new SettingsFlyout { Title = commandLabel, Content = view, HorizontalContentAlignment = HorizontalAlignment.Stretch }; // extract the header color/logo from the appmanifest.xml var visualElements = await AppManifestHelper.GetManifestVisualElementsAsync(); // enable the overriding of these, but default to manifest var headerBackground = viewSettings.ContainsKey("headerbackground") ? (SolidColorBrush)viewSettings["headerbackground"] : new SolidColorBrush(visualElements.BackgroundColor); var smallLogoUri = viewSettings.ContainsKey("smalllogouri") ? (Uri)viewSettings["smalllogouri"] : visualElements.SmallLogoUri; var smallLogo = new BitmapImage(smallLogoUri); // use real property names for ApplySettings if (!viewSettings.ContainsKey("HeaderBackground")) { viewSettings["HeaderBackground"] = headerBackground; } if (!viewSettings.ContainsKey("IconSource")) { viewSettings["IconSource"] = smallLogo; } ApplySettings(settingsFlyout, viewSettings); var deactivator = viewModel as IDeactivate; if (deactivator != null) { RoutedEventHandler closed = null; closed = (s, e) => { settingsFlyout.Unloaded -= closed; deactivator.Deactivate(true); }; settingsFlyout.Unloaded += closed; } var activator = viewModel as IActivate; if (activator != null) { activator.Activate(); } if (independent) { settingsFlyout.ShowIndependent(); } else { settingsFlyout.Show(); } }
/// <summary> /// Occurs after navigation /// </summary> /// <param name="sender"> The event sender. </param> /// <param name="e"> The event args. </param> protected virtual void OnNavigated(object sender, NavigationEventArgs e) { if (e.Uri.IsAbsoluteUri || e.Content == null) { return; } ViewLocator.InitializeComponent(e.Content); // Do not use LocateForView because Frame control already has its // parent's DataContext. Use LocateForViewType instead. var viewModel = ViewModelLocator.LocateForViewType(e.Content.GetType()); //var viewModel = ViewModelLocator.LocateForView(e.Content); if (viewModel == null) { if (System.Diagnostics.Debugger.IsAttached) { var msg = "'" + e.Content.GetType().FullName + "' must be registered in the bootstrapper (or INavigationService might never get injected)"; var exc = new InvalidOperationException(msg); LogManager.GetLog(typeof(FrameAdapter)).Error(exc); throw exc; } return; } // Inject dependency properties IoC.BuildUp(viewModel); #if WINDOWS_PHONE var page = e.Content as PhoneApplicationPage; #else var page = e.Content as Page; #endif if (page == null) { throw new ArgumentException("View '" + e.Content.GetType().FullName + "' should inherit from PhoneApplicationPage or one of its descendents."); } if (treatViewAsLoaded) { page.SetValue(View.IsLoadedProperty, true); } TryInjectQueryString(viewModel, page); ViewModelBinder.Bind(viewModel, page, null); var activator = viewModel as IActivate; if (activator != null) { activator.Activate(); } #if WINDOWS_PHONE || WinRT var page = e.Content as PhoneApplicationPage; var viewAware = viewModel as IViewAware; if (viewAware != null) { View.ExecuteOnLayoutUpdated(page, (s, a) => viewAware.OnViewReady(page)); } #endif GC.Collect(); }
/// <summary> /// Shows a modal dialog for the specified model. /// </summary> /// <param name="rootModel">The root model.</param> /// <param name="context">The context.</param> public void ShowDialog(object rootModel, object context = null) { var view = EnsureWindow(rootModel, ViewLocator.LocateForModel(rootModel, null, context)); ViewModelBinder.Bind(rootModel, view, context); var haveDisplayName = rootModel as IHaveDisplayName; if (haveDisplayName != null && !ConventionManager.HasBinding(view, ChildWindow.TitleProperty)) { var binding = new Binding("DisplayName") { Mode = BindingMode.TwoWay }; view.SetBinding(ChildWindow.TitleProperty, binding); } var activatable = rootModel as IActivate; if (activatable != null) { activatable.Activate(); } var deactivatable = rootModel as IDeactivate; if (deactivatable != null) { bool deactivatingFromView = false; bool deactivateFromVM = false; view.Closed += (s, e) => { if (deactivateFromVM) { return; } deactivatingFromView = true; deactivatable.Deactivate(true); deactivatingFromView = false; }; deactivatable.Deactivated += (s, e) => { if (e.WasClosed && !deactivatingFromView) { deactivateFromVM = true; actuallyClosing = true; view.Close(); actuallyClosing = false; deactivateFromVM = false; } }; } var guard = rootModel as IGuardClose; if (guard != null) { view.Closing += (s, e) => OnShutdownAttempted(guard, view, e); } view.Show(); }
/// <summary> /// Shows a settings flyout panel for the specified model. /// </summary> /// <param name="viewModel">The settings view model.</param> /// <param name="commandLabel">The settings command label.</param> /// <param name="viewSettings">The optional dialog settings.</param> public async void ShowSettingsFlyout(object viewModel, string commandLabel, IDictionary <string, object> viewSettings = null) { var view = ViewLocator.LocateForModel(viewModel, null, null); ViewModelBinder.Bind(viewModel, view, null); viewSettings = viewSettings ?? new Dictionary <string, object>(); var width = viewSettings.ContainsKey("width") ? (SettingsFlyout.SettingsFlyoutWidth)viewSettings["width"] : SettingsFlyout.SettingsFlyoutWidth.Narrow; // extract the header color/logo from the appmanifest.xml var visualElements = await Callisto.Controls.Common.AppManifestHelper.GetManifestVisualElementsAsync(); // enable the overriding of these, but default to manifest var headerBackground = viewSettings.ContainsKey("headerbackground") ? (SolidColorBrush)viewSettings["headerbackground"] : new SolidColorBrush(visualElements.BackgroundColor); var smallLogoUri = viewSettings.ContainsKey("smalllogouri") ? (Uri)viewSettings["smalllogouri"] : visualElements.SmallLogoUri; var smallLogo = new BitmapImage(smallLogoUri); // use real property names for ApplySettings if (!viewSettings.ContainsKey("FlyoutWidth")) { viewSettings["FlyoutWidth"] = width; } if (!viewSettings.ContainsKey("HeaderBrush")) { viewSettings["HeaderBrush"] = headerBackground; } if (!viewSettings.ContainsKey("SmallLogoImageSource")) { viewSettings["SmallLogoImageSource"] = smallLogo; } var settingsFlyout = new SettingsFlyout { HeaderText = commandLabel, Content = view, }; ApplySettings(settingsFlyout, viewSettings); settingsFlyout.IsOpen = true; var deactivator = viewModel as IDeactivate; if (deactivator != null) { EventHandler <object> closed = null; closed = (s, e) => { settingsFlyout.Closed -= closed; deactivator.Deactivate(true); }; settingsFlyout.Closed += closed; } var activator = viewModel as IActivate; if (activator != null) { activator.Activate(); } }