Binds a view to a view model.
Exemple #1
0
        public virtual void ShowPopup(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);
            Caliburn.Micro.Action.SetTargetWithoutContext(view, rootModel);

            var activatable = rootModel as IActivate;

            if (activatable != null)
            {
                activatable.Activate();
            }

            var deactivator = rootModel as IDeactivate;

            if (deactivator != null)
            {
                popup.Closed += delegate { deactivator.Deactivate(true); };
            }

            popup.IsOpen = true;
            //popup.CaptureMouse();
        }
Exemple #2
0
        static void ModelChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            if (Execute.InDesignMode || e.NewValue == null || e.NewValue == e.OldValue)
            {
                return;
            }

            var fe = d as FrameworkElement;

            if (fe == null)
            {
                return;
            }

            View.ExecuteOnLoad(fe, delegate
            {
                var target       = e.NewValue;
                var containerKey = e.NewValue as string;

                if (containerKey != null)
                {
                    target = IoC.GetInstance(null, containerKey);
                }

                d.SetValue(View.IsScopeRootProperty, true);

                var context = string.IsNullOrEmpty(fe.Name)
                                  ? fe.GetHashCode().ToString()
                                  : fe.Name;

                ViewModelBinder.Bind(target, d, context);
            });
        }
Exemple #3
0
        static void OnModelChanged(DependencyObject targetLocation, DependencyPropertyChangedEventArgs args)
        {
            if (args.OldValue == args.NewValue)
            {
                return;
            }

            if (args.NewValue != null)
            {
                var context = GetContext(targetLocation);

                var view = ViewLocator.LocateForModel(args.NewValue, targetLocation, context);
                ViewModelBinder.Bind(args.NewValue, view, context);
                if (!SetContentProperty(targetLocation, view))
                {
                    Log.Warn("SetContentProperty failed for ViewLocator.LocateForModel, falling back to LocateForModelType");

                    view = ViewLocator.LocateForModelType(args.NewValue.GetType(), targetLocation, context);

                    SetContentProperty(targetLocation, view);
                }
            }
            else
            {
                SetContentProperty(targetLocation, args.NewValue);
            }
        }
        /// <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 navigationSvc = IoC.Get <INavigationService>();

            var host = new DialogHost(navigationSvc);
            var view = ViewLocator.LocateForModel(rootModel, host, context);

            host.Content = view;
            host.SetValue(View.IsGeneratedProperty, true);

            ViewModelBinder.Bind(rootModel, host, null);
            host.SetActionTarget(rootModel);

            ApplySettings(host, settings);

            var activatable = rootModel as IActivate;

            if (activatable != null)
            {
                activatable.Activate();
            }

            var deactivator = rootModel as IDeactivate;

            if (deactivator != null)
            {
                host.Closed += delegate { deactivator.Deactivate(true); };
            }

            host.Open();
        }
        static void ModelChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            if (Bootstrapper.IsInDesignMode || e.NewValue == null || e.NewValue == e.OldValue)
            {
                return;
            }

            var fe = d as FrameworkElement;

            if (fe == null)
            {
                return;
            }

            RoutedEventHandler handler = null;

            handler = delegate {
                var target       = e.NewValue;
                var containerKey = e.NewValue as string;

                if (containerKey != null)
                {
                    target = IoC.GetInstance(null, containerKey);
                }

                d.SetValue(View.IsLoadedProperty, true);
                ViewModelBinder.Bind(target, d, null);
                fe.Loaded -= handler;
            };

            fe.Loaded += handler;
        }
Exemple #6
0
        private Task PushAsync(Element view, object parameter, bool animated)
        {
            var page = view as Page;

            if (page == null && !(view is ContentView))
            {
                throw new NotSupportedException(String.Format("{0} does not inherit from either {1} or {2}.", view.GetType(), typeof(Page), typeof(ContentView)));
            }

            var viewModel = ViewModelLocator.LocateForView(view);

            if (viewModel != null)
            {
                TryInjectParameters(viewModel, parameter);

                ViewModelBinder.Bind(viewModel, view, null);
            }

            var contentView = view as ContentView;

            if (contentView != null)
            {
                page = CreateContentPage(contentView, viewModel);
            }

            return(navigationPage.PushAsync(page, animated));
        }
Exemple #7
0
        /// <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)
            {
                return;
            }

            ViewLocator.InitializeComponent(e.Content);

            var viewModel = ViewModelLocator.LocateForView(e.Content);

            if (viewModel == null)
            {
                return;
            }

            ViewModelBinder.Bind(viewModel, (DependencyObject)e.Content, null);

            TryInjectQueryString(viewModel, e.Content);

            var activator = viewModel as IActivate;

            if (activator != null)
            {
                activator.Activate();
            }
        }
Exemple #8
0
        static void ModelChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            if (View.InDesignMode || e.NewValue == null || e.NewValue == e.OldValue)
            {
                return;
            }

            var fe = d as FrameworkElement;

            if (fe == null)
            {
                return;
            }

            View.ExecuteOnLoad(fe, delegate {
                var target = e.NewValue;

                d.SetValue(View.IsScopeRootProperty, true);

#if XFORMS
                var context = fe.Id.ToString("N");
#else
                var context = string.IsNullOrEmpty(fe.Name)
                                  ? fe.GetHashCode().ToString()
                                  : fe.Name;
#endif

                ViewModelBinder.Bind(target, d, context);
            });
        }
        /// <summary>
        /// Shows a toast notification for the specified model.
        /// </summary>
        /// <param name="rootModel">The root model.</param>
        /// <param name="durationInMilliseconds">How long the notification should appear for.</param>
        /// <param name="context">The context.</param>
        /// <param name="settings">The optional notification settings.</param>
        public virtual void ShowNotification(object rootModel, int durationInMilliseconds, object context = null, IDictionary <string, object> settings = null)
        {
            var window = new NotificationWindow();
            var view   = ViewLocator.LocateForModel(rootModel, window, context);

            ViewModelBinder.Bind(rootModel, view, null);
            window.Content = (FrameworkElement)view;

            ApplySettings(window, settings);

            var activator = rootModel as IActivate;

            if (activator != null)
            {
                activator.Activate();
            }

            var deactivator = rootModel as IDeactivate;

            if (deactivator != null)
            {
                window.Closed += delegate { deactivator.Deactivate(true); };
            }

            window.Show(durationInMilliseconds);
        }
Exemple #10
0
        /// <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 async Task <Window> CreateWindowAsync(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 (string.IsNullOrEmpty(view.Title) && haveDisplayName != null && !ConventionManager.HasBinding(view, Window.TitleProperty))
            {
                var binding = new Binding("DisplayName")
                {
                    Mode = BindingMode.TwoWay
                };
                view.SetBinding(Window.TitleProperty, binding);
            }

            ApplySettings(view, settings);

            var conductor = new WindowConductor(rootModel, view);

            await conductor.InitialiseAysnc();

            return(view);
        }
Exemple #11
0
        static void DataContextChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            if (!View.InDesignMode)
            {
                return;
            }

            var enable = d.GetValue(AtDesignTimeProperty);

            if (enable == null || ((bool)enable) == false || e.NewValue == null)
            {
                return;
            }

            var fe = d as FrameworkElement;

            if (fe == null)
            {
                return;
            }
#if XFORMS
            ViewModelBinder.Bind(e.NewValue, d, fe.Id.ToString("N"));
#else
            ViewModelBinder.Bind(e.NewValue, d, string.IsNullOrEmpty(fe.Name) ? fe.GetHashCode().ToString() : fe.Name);
#endif
        }
        /// <summary>
        /// Creates the page.
        /// </summary>
        /// <param name="rootModel">The root model.</param>
        /// <param name="context">The context.</param>
        /// <returns></returns>
        public virtual Page CreatePage(object rootModel, object context)
        {
            var view = EnsurePage(rootModel, ViewLocator.LocateForModel(rootModel, null, context));

            ViewModelBinder.Bind(rootModel, view, context);

            var haveDisplayName = rootModel as IHaveDisplayName;

            if (haveDisplayName != null && !ConventionManager.HasBinding(view, Page.TitleProperty))
            {
                var binding = new Binding("DisplayName")
                {
                    Mode = BindingMode.TwoWay
                };
                view.SetBinding(Page.TitleProperty, binding);
            }

            var activatable = rootModel as IActivate;

            if (activatable != null)
            {
                activatable.Activate();
            }

            var deactivatable = rootModel as IDeactivate;

            if (deactivatable != null)
            {
                view.Unloaded += (s, e) => deactivatable.Deactivate(true);
            }

            return(view);
        }
Exemple #13
0
        static void OnContextChanged(DependencyObject targetLocation, DependencyPropertyChangedEventArgs e)
        {
            if (e.OldValue == e.NewValue)
            {
                return;
            }

            var model = GetModel(targetLocation);

            if (model == null)
            {
                return;
            }

            var view = ViewLocator.LocateForModel(model, targetLocation, e.NewValue);

            if (!SetContentProperty(targetLocation, view))
            {
                Log.Warn("SetContentProperty failed for ViewLocator.LocateForModel, falling back to LocateForModelType");

                view = ViewLocator.LocateForModelType(model.GetType(), targetLocation, e.NewValue);

                SetContentProperty(targetLocation, view);
            }

            ViewModelBinder.Bind(model, view, e.NewValue);
        }
Exemple #14
0
        /// <summary>
        /// Creates the page.
        /// </summary>
        /// <param name="rootModel">The root model.</param>
        /// <param name="context">The context.</param>
        /// <param name="settings">The optional popup settings.</param>
        /// <returns>The page.</returns>
        public virtual async Task <Page> CreatePageAsync(object rootModel, object context, IDictionary <string, object> settings)
        {
            var view = EnsurePage(rootModel, ViewLocator.LocateForModel(rootModel, null, context));

            ViewModelBinder.Bind(rootModel, view, context);

            var haveDisplayName = rootModel as IHaveDisplayName;

            if (string.IsNullOrEmpty(view.Title) && haveDisplayName != null && !ConventionManager.HasBinding(view, Page.TitleProperty))
            {
                var binding = new Binding("DisplayName")
                {
                    Mode = BindingMode.TwoWay
                };
                view.SetBinding(Page.TitleProperty, binding);
            }

            ApplySettings(view, settings);

            if (rootModel is IActivate activator)
            {
                await activator.ActivateAsync();
            }

            if (rootModel is IDeactivate deactivatable)
            {
                view.Unloaded += async(s, e) => await deactivatable.DeactivateAsync(true);
            }

            return(view);
        }
Exemple #15
0
        static void ModelWithoutContextChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            if (View.InDesignMode || e.NewValue == null || e.NewValue == e.OldValue)
            {
                return;
            }

            var fe = d as FrameworkElement;

            if (fe == null)
            {
                return;
            }

            View.ExecuteOnLoad(fe, delegate {
                var target       = e.NewValue;
                var containerKey = e.NewValue as string;
                if (containerKey != null)
                {
                    LogManager.GetLog(typeof(Bind)).Info("Using IoC is deprecated and will be removed in v3.0");
                    target = IoC.GetInstance(null, containerKey);
                }

                d.SetValue(View.IsScopeRootProperty, true);

                var context = string.IsNullOrEmpty(fe.Name)
                                  ? fe.GetHashCode().ToString()
                                  : fe.Name;

                d.SetValue(NoContextProperty, true);
                ViewModelBinder.Bind(target, d, context);
            });
        }
Exemple #16
0
        /// <summary>
        /// Binds the view model.
        /// </summary>
        /// <param name="view">The view.</param>
        protected virtual void BindViewModel(DependencyObject view)
        {
            ViewLocator.InitializeComponent(view);

            var viewModel = ViewModelLocator.LocateForView(view);

            if (viewModel == null)
            {
                return;
            }

            if (treatViewAsLoaded)
            {
                view.SetValue(View.IsLoadedProperty, true);
            }

            TryInjectParameters(viewModel, currentParameter);
            ViewModelBinder.Bind(viewModel, view, null);

            var activator = viewModel as IActivate;

            if (activator != null)
            {
                activator.Activate();
            }
        }
        /// <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);

            var settingsFlyout = new SettingsFlyout
            {
                FlyoutWidth          = width,
                HeaderText           = commandLabel,
                Content              = view,
                IsOpen               = true,
                HeaderBrush          = headerBackground,
                SmallLogoImageSource = smallLogo
            };

            var deactivator = viewModel as IDeactivate;

            if (deactivator != null)
            {
                EventHandler <object> closed = null;
                closed = (s, e) => {
                    deactivator.Deactivate(true);
                    settingsFlyout.Closed -= closed;
                };

                settingsFlyout.Closed += closed;
            }

            var activator = viewModel as IActivate;

            if (activator != null)
            {
                activator.Activate();
            }
        }
        protected virtual void OnNavigated(object sender, NavigationEventArgs e)
        {
            if (e.Content == null)
            {
                return;
            }

            ViewLocator.InitializeComponent(e.Content);

            var viewModel = ViewModelLocator.LocateForView(e.Content);

            if (viewModel == null)
            {
                return;
            }

            var view = e.Content as Page;

            if (view == null)
            {
                throw new ArgumentException("View '" + e.Content.GetType().FullName + "' should inherit from Page or one of its descendents.");
            }

            if (treatViewAsLoaded)
            {
                view.SetValue(View.IsLoadedProperty, true);
            }

            TryInjectParameter(viewModel, e.Parameter);

            ViewModelBinder.Bind(viewModel, view, null);

            var activator = viewModel as IActivate;

            if (activator != null)
            {
                activator.Activate();
            }

            var viewAware = viewModel as ViewAware;

            if (viewAware != null)
            {
                EventHandler <object> onLayoutUpdate = null;

                onLayoutUpdate = delegate
                {
                    viewAware.OnViewReady(view);
                    view.LayoutUpdated -= onLayoutUpdate;
                };

                view.LayoutUpdated += onLayoutUpdate;
            }

            GC.Collect(); // Why?
        }
Exemple #19
0
        /// <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);

            var viewModel = ViewModelLocator.LocateForView(e.Content);

            if (viewModel == null)
            {
                return;
            }

            var page = e.Content as PhoneApplicationPage;

            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);
            }

            ViewModelBinder.Bind(viewModel, page, null);

            TryInjectQueryString(viewModel, page);

            var activator = viewModel as IActivate;

            if (activator != null)
            {
                activator.Activate();
            }

            var viewAware = viewModel as ViewAware;

            if (viewAware != null)
            {
                EventHandler onLayoutUpdate = null;
                onLayoutUpdate = delegate {
                    viewAware.OnViewReady(page);
                    page.LayoutUpdated -= onLayoutUpdate;
                };
                page.LayoutUpdated += onLayoutUpdate;
            }

            GC.Collect();
        }
Exemple #20
0
        private static Tuple <T, UIElement> CreateViewModelAndView <T>(Action <T> onInitialize = null) where T : IScreen
        {
            var vm   = IoC.Get <T>();
            var view = ViewLocator.LocateForModel(vm, null, null);

            ViewModelBinder.Bind(vm, view, null);

            if (onInitialize != null)
            {
                onInitialize(vm);
            }

            ScreenExtensions.TryActivate(vm);

            return(new Tuple <T, UIElement>(vm, view));
        }
Exemple #21
0
        /// <summary>
        /// Locates the view model, locates the associate view, binds them and shows it as the root view.
        /// </summary>
        /// <param name="application">The application.</param>
        /// <param name="viewModelType">The view model type.</param>
        protected static void DisplayRootViewFor(Application application, Type viewModelType)
        {
            var viewModel = IoC.GetInstance(viewModelType, null);
            var view      = ViewLocator.LocateForModel(viewModel, null, null);

            ViewModelBinder.Bind(viewModel, view, null);

            var activator = viewModel as IActivate;

            if (activator != null)
            {
                activator.Activate();
            }

            Mouse.Initialize(view);
            application.RootVisual = view;
        }
        /// <summary>
        /// Locates the view model, locates the associate view, binds them and shows it as the root view.
        /// </summary>
        /// <param name="viewModelType">The view model type.</param>
        /// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
        /// <returns>A task that represents the asynchronous operation.</returns>
        protected async Task DisplayRootViewForAsync(Type viewModelType, CancellationToken cancellationToken)
        {
            Initialize();

            var viewModel = IoC.GetInstance(viewModelType, null);
            var view      = ViewLocator.LocateForModel(viewModel, null, null);

            ViewModelBinder.Bind(viewModel, view, null);

            if (viewModel is IActivate activator)
            {
                await activator.ActivateAsync(cancellationToken);
            }

            Window.Current.Content = view;
            Window.Current.Activate();
        }
Exemple #23
0
        private static void UpdateViewModel(DependencyObject dependencyObject)
        {
            var model   = GetModel(dependencyObject);
            var context = GetContext(dependencyObject);

            if (model == null)
            {
                SetContentProperty(dependencyObject, null);
                return;
            }

            var view = ViewLocator.LocateForModel(model, dependencyObject, context);

            SetContentProperty(dependencyObject, view);

            ViewModelBinder.Bind(model, view, context);
        }
Exemple #24
0
        static void OnContextChanged(DependencyObject targetLocation, DependencyPropertyChangedEventArgs e)
        {
            if (e.OldValue == e.NewValue)
            {
                return;
            }

            var model = GetModel(targetLocation);

            if (model == null)
            {
                return;
            }

            var view = ViewLocator.LocateForModel(model, targetLocation, e.NewValue);

            SetContentProperty(targetLocation, view);
            ViewModelBinder.Bind(model, view, e.NewValue);
        }
        /// <summary>
        /// Locates the view model, locates the associate view, binds them and shows it as the root view.
        /// </summary>
        /// <param name="viewModelType">The view model type.</param>
        protected void DisplayRootViewFor(Type viewModelType)
        {
            Initialise();

            var viewModel = IoC.GetInstance(viewModelType, null);
            var view      = ViewLocator.LocateForModel(viewModel, null, null);

            ViewModelBinder.Bind(viewModel, view, null);

            var activator = viewModel as IActivate;

            if (activator != null)
            {
                activator.Activate();
            }

            Window.Current.Content = view;
            Window.Current.Activate();
        }
        /// <summary>
        /// Locates the view model, locates the associate view, binds them and shows it as the root view.
        /// </summary>
        /// <param name="viewModelType">The view model type.</param>
        protected async Task DisplayRootViewForAsync(Type viewModelType)
        {
            var viewModel = IoC.GetInstance(viewModelType, null);
            var view      = ViewLocator.LocateForModel(viewModel, null, null);

            if (!(view is Page page))
            {
                throw new NotSupportedException(String.Format("{0} does not inherit from {1}.", view.GetType(), typeof(Page)));
            }

            ViewModelBinder.Bind(viewModel, view, null);

            if (viewModel is IActivate activator)
            {
                await activator.ActivateAsync();
            }

            MainPage = page;
        }
Exemple #27
0
        static void OnModelChanged(DependencyObject targetLocation, DependencyPropertyChangedEventArgs args)
        {
            if (args.OldValue == args.NewValue)
            {
                return;
            }

            if (args.NewValue != null)
            {
                var context = GetContext(targetLocation);
                var view    = ViewLocator.LocateForModel(args.NewValue, targetLocation, context);

                SetContentProperty(targetLocation, view);
                ViewModelBinder.Bind(args.NewValue, view, context);
            }
            else
            {
                SetContentProperty(targetLocation, args.NewValue);
            }
        }
        /// <summary>
        ///     Locates the view model, locates the associate view, binds them and shows it as the root view.
        /// </summary>
        /// <param name="viewModelType">The view model type.</param>
        protected void DisplayRootViewFor(Type viewModelType)
        {
            var rootElement    = NoesisView.Content;
            var contentControl = (ContentControl)rootElement.FindName(RootContentControlName);

            object viewModel = IoC.GetInstance(viewModelType, null);

            UIElement view = ViewLocator.LocateForModel(viewModel, null, null);

            ViewModelBinder.Bind(viewModel, view, null);

            var activator = viewModel as IActivate;

            if (activator != null)
            {
                activator.Activate();
            }

            contentControl.Content = view;
        }
Exemple #29
0
        /// <summary>
        /// Shows a modal dialog for the specified model.
        /// </summary>
        /// <param name="rootModel">The root model.</param>
        /// <param name="context">The context.</param>
        public virtual 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);
            }

            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>
        /// <returns>The window.</returns>
        protected virtual Window CreateWindow(object rootModel, bool isDialog, object context)
        {
            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);
            }

            new WindowConductor(rootModel, view);

            return(view);
        }