Example #1
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);
        }
Example #2
0
        /// <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);
        }
Example #3
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);
        }
Example #4
0
        ///<summary>
        ///  Checks if the <see cref="ActionMessage" /> -Target was set.
        ///</summary>
        ///<param name="element"> DependencyObject to check </param>
        ///<returns> True if Target or TargetWithoutContext was set on <paramref name="element" /> </returns>
        public static bool HasTargetSet(DependencyObject element)
        {
            if (GetTarget(element) != null || GetTargetWithoutContext(element) != null)
            {
                return(true);
            }

            var frameworkElement = element as FrameworkElement;

            if (frameworkElement == null)
            {
                return(false);
            }

            return(ConventionManager.HasBinding(frameworkElement, TargetProperty) ||
                   ConventionManager.HasBinding(frameworkElement, TargetWithoutContextProperty));
        }
Example #5
0
        public static void Install()
        {
            ConventionManager.AddElementConvention <RadBusyIndicator>(RadBusyIndicator.IsRunningProperty,
                                                                      "IsRunning",
                                                                      "Loaded");
            ConventionManager.AddElementConvention <RadDataBoundListBox>(DataControlBase.ItemsSourceProperty,
                                                                         "SelectedItem",
                                                                         "SelectionChanged")
            .ApplyBinding = (viewModelType, path, property, element, convention) =>
            {
                if (!ConventionManager.SetBindingWithoutBindingOrValueOverwrite(viewModelType,
                                                                                path,
                                                                                property, element, convention,
                                                                                DataControlBase.ItemsSourceProperty))
                {
                    return(false);
                }

                if (ConventionManager.HasBinding(element, RadDataBoundListBox.SelectedItemProperty))
                {
                    return(true);
                }

                var index = path.LastIndexOf('.');
                index = index == -1 ? 0 : index + 1;

                var baseName = path.Substring(index);
                foreach (var selectionPath in
                         from potentialName in ConventionManager.DerivePotentialSelectionNames(baseName)
                         where
                         viewModelType.GetProperty(potentialName,
                                                   BindingFlags.IgnoreCase | BindingFlags.Public |
                                                   BindingFlags.Instance) != null
                         select path.Replace(baseName, potentialName))
                {
                    var binding = new Binding(selectionPath)
                    {
                        Mode = BindingMode.TwoWay
                    };
                    BindingOperations.SetBinding(element, RadDataBoundListBox.SelectedItemProperty, binding);
                }

                return(true);
            };
        }
Example #6
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>
        /// <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);
        }
Example #7
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();
        }
Example #8
0
        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);
        }
Example #9
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 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();
        }