Пример #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>
        protected virtual Page CreatePage(object rootModel, string context, IDictionary <string, object> settings)
        {
            var view = EnsurePage(rootModel, _viewModelLocator.LocateForModel(rootModel, context));

            _viewModelBinder.Bind(rootModel, view, context);

            var haveDisplayName = rootModel as IHaveDisplayName;

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

            ApplySettings(view, settings);

            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);
        }
Пример #2
0
        /// <summary>
        /// Updates the Enabled state of the target element based on the CanExecute method of the command.
        /// </summary>
        protected void UpdateEnabledState()
        {
            if (AssociatedObject == null)
            {
                return;
            }

            var canExecute = true;

            if (Command != null)
            {
                var resolvedParameter = DetermineParameter();
                canExecute = Command.CanExecute(resolvedParameter);
            }

#if NETFX_CORE
            var control = AssociatedObject as Control;
            if (control != null && !BindingHelper.IsDataBound(control, Control.IsEnabledProperty))
            {
                control.IsEnabled = canExecute;
            }
#else
            var control = AssociatedObject as FrameworkElement;
            if (control != null && !BindingHelper.IsDataBound(control, UIElement.IsEnabledProperty))
            {
                control.IsEnabled = canExecute;
            }
#endif
        }
Пример #3
0
        /// <summary>
        /// Forces an update of the IsEnabled state.
        /// </summary>
        public void UpdateEnabledState()
        {
            if (AssociatedObject == null)
            {
                return;
            }

            var canExecute = true;

            if (_guard != null)
            {
                var parameterValues = DetermineParameters(_guard);
                canExecute = (bool)_guard.Invoke(Target, parameterValues);
            }

#if NETFX_CORE
            var control = AssociatedObject as Control;
            if (control != null && !BindingHelper.IsDataBound(control, Control.IsEnabledProperty))
            {
                control.IsEnabled = canExecute;
            }
#else
            var control = AssociatedObject as FrameworkElement;
            if (control != null && !BindingHelper.IsDataBound(control, UIElement.IsEnabledProperty))
            {
                control.IsEnabled = canExecute;
            }
#endif
        }
Пример #4
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 Window CreateWindow(object rootModel, bool isDialog, string context,
                                              IDictionary <string, object> settings)
        {
            var view = EnsureWindow(rootModel, _viewModelLocator.LocateForModel(rootModel, context), isDialog);

            _viewModelBinder.Bind(rootModel, view, context);

            var haveDisplayName = rootModel as IHaveDisplayName;

            if (haveDisplayName != null && !BindingHelper.IsDataBound(view, Window.TitleProperty))
            {
                var binding = new Binding("DisplayName")
                {
                    Mode = BindingMode.OneWay
                };
                view.SetBinding(Window.TitleProperty, binding);
            }

            ApplySettings(view, settings);

            var conductor = new WindowConductor(rootModel, view);

            return(conductor.View);
        }