Example #1
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
        }
        /// <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
        }
Example #3
0
 private static void RefreshDataBindingsOnActions(TriggerActionCollection actions)
 {
     foreach (var target in actions)
     {
         foreach (var property in BindingHelper.GetDependencyProperties(target.GetType()))
         {
             BindingHelper.RefreshBinding(target, property);
         }
     }
 }
Example #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);
        }