// <summary>
        // Basic ctor
        // </summary>
        // <param name="container"></param>
        public PropertyContainerAutomationPeer(PropertyContainer container)
            : base(container) 
        {
            if (container == null)
            {
                throw FxTrace.Exception.ArgumentNull("container");
            }

            _container = container;
        }
 private void DisassociateContainerEventHandlers(PropertyContainer container) {
     if (_attachedToContainerEvents) {
         container.DependencyPropertyChanged -= new DependencyPropertyChangedEventHandler(OnPropertyContainerDependencyPropertyChanged);
         _attachedToContainerEvents = false;
     }
 }
 private void AssociateContainerEventHandlers(PropertyContainer container) {
     if (!_attachedToContainerEvents) {
         container.DependencyPropertyChanged += new DependencyPropertyChangedEventHandler(OnPropertyContainerDependencyPropertyChanged);
         _attachedToContainerEvents = true;
     }
 }
        /// <summary>
        /// Called when any DependencyProperties of this Control change.  If you override
        /// this method, call the base implementation first to preserve the desired functionality.
        /// </summary>
        /// <param name="e">Event args</param>
        protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e) {
            // Check to see if this control has changed (or gained or lost) its owning PropertyContainer.
            // If so, it may need to update its state / appearance accordingly
            if (e.Property == PropertyContainer.OwningPropertyContainerProperty) {
                PropertyContainer oldContainer = (PropertyContainer)e.OldValue;
                PropertyContainer newContainer = (PropertyContainer)e.NewValue;
                _owningContainer = newContainer;

                if (oldContainer != null)
                    DisassociateContainerEventHandlers(oldContainer);

                if (newContainer != null)
                    AssociateContainerEventHandlers(newContainer);

                this.CoerceValue(TargetEditModeProperty);
            }

            base.OnPropertyChanged(e);
        }
        private void OnOwningPropertyContainerChanged(PropertyContainer oldValue, PropertyContainer newValue) 
        {
            if (oldValue != null) 
            {
                PropertySelection.ClearSelectionStop(oldValue);
                PropertySelection.ClearIsSelectionStopDoubleClickTarget(oldValue);
            }

            if (newValue != null) 
            {
                PropertySelection.SetSelectionStop(newValue, this);
                PropertySelection.SetIsSelectionStopDoubleClickTarget(newValue, true);
            }
        }
Example #6
0
        private static object OnCoerceEditModeProperty(DependencyObject obj, object value)
        {
            EditModeSwitchButton theThis = (EditModeSwitchButton)obj;

            // [....] to the owning PropertyContainer only if requested to do so
            if (!theThis.SyncModeToOwningContainer)
            {
                return(value);
            }

            // Do we have an owning PropertyContainer?
            if (theThis._owningContainer == null)
            {
                return(value);
            }

            PropertyContainerEditMode newMode;
            PropertyContainer         owningContainer = theThis._owningContainer;

            switch (owningContainer.ActiveEditMode)
            {
            case PropertyContainerEditMode.Inline:
                // when clicked, have this button switch to extended popup mode
                // or dialog mode (dialog takes precedence)
                if (owningContainer.SupportsEditMode(PropertyContainerEditMode.Dialog))
                {
                    newMode = PropertyContainerEditMode.Dialog;
                }
                else if (owningContainer.SupportsEditMode(PropertyContainerEditMode.ExtendedPopup))
                {
                    newMode = PropertyContainerEditMode.ExtendedPopup;
                }
                else
                {
                    newMode = PropertyContainerEditMode.Inline;
                }

                break;

            case PropertyContainerEditMode.ExtendedPopup:
                // when clicked, have this button switch to extended pinned mode
                newMode = PropertyContainerEditMode.ExtendedPinned;
                break;

            case PropertyContainerEditMode.ExtendedPinned:
                // when clicked, have this button switch to inline mode
                newMode = PropertyContainerEditMode.Inline;
                break;

            case PropertyContainerEditMode.Dialog:
                // do nothing
                newMode = theThis.TargetEditMode;
                break;

            default:
                Debug.Fail(string.Format(
                               System.Globalization.CultureInfo.CurrentCulture,
                               "ModeSwitchControl does not yet support PropertyContainerEditMode '{0}'.",
                               owningContainer.ActiveEditMode.ToString()));
                newMode = (PropertyContainerEditMode)value;
                break;
            }

            return(newMode);
        }
 // <summary>
 // Private method to unhook the ValueChanged event.
 // </summary>
 // <param name="expander">Expander</param>
 // <param name="valueChangedEvent">ValueChanged event</param>
 private static void UnHookFocusEvents(PropertyContainer container, EventHandler valueChangedEvent) 
 {
     if (container != null) 
     {
         DependencyPropertyDescriptor dpd = DependencyPropertyDescriptor.FromProperty(PropertySelection.IsSelectedProperty, typeof(PropertyContainer));
         if (dpd != null) 
         {
             dpd.RemoveValueChanged(container, valueChangedEvent);
         }
     }
 }
        /// <summary>
        /// Setter for attached, inherited DP that can be used by UI elements of PropertyValueEditors
        /// to gain access to their parent PropertyContainer.
        /// </summary>
        /// <param name="dependencyObject">The DO to set the property on</param>
        /// <param name="value">The Owning PropertyContainer</param>
        public static void SetOwningPropertyContainer(DependencyObject dependencyObject, PropertyContainer value)
        {
            if (dependencyObject == null)
            {
                throw FxTrace.Exception.ArgumentNull("dependencyObject");
            }

            dependencyObject.SetValue(PropertyContainer.OwningPropertyContainerProperty, value);
        }
        // Updates the ControlTemplate of this control based on the currently ActiveEditMode
        private static void UpdateControlTemplate(PropertyContainer container)
        {

            PropertyContainerEditMode editMode = container.ActiveEditMode;
            ControlTemplate newTemplate = null;

            switch (editMode)
            {
                case PropertyContainerEditMode.Inline:
                    newTemplate = container.InlineRowTemplate;
                    break;
                case PropertyContainerEditMode.ExtendedPopup:
                    newTemplate = container.ExtendedPopupRowTemplate;
                    break;
                case PropertyContainerEditMode.ExtendedPinned:
                    newTemplate = container.ExtendedPinnedRowTemplate;
                    break;
                case PropertyContainerEditMode.Dialog:
                    // In dialog case, just keep the same value
                    return;
                default:
                    Debug.Fail(
                        string.Format(
                            System.Globalization.CultureInfo.CurrentCulture,
                            "PropertyContainerEditMode does not yet support PropertyContainerEditMode '{0}'.",
                            editMode.ToString()));
                    newTemplate = container.Template;
                    break;
            }

            if (newTemplate != container.Template)
                container.Template = newTemplate;
        }
        /// <summary>
        /// Setter for attached, inherited DP that can be used by UI elements of PropertyValueEditors
        /// to gain access to their parent PropertyContainer.
        /// </summary>
        /// <param name="dependencyObject">The DO to set the property on</param>
        /// <param name="value">The Owning PropertyContainer</param>
        public static void SetOwningPropertyContainer(DependencyObject dependencyObject, PropertyContainer value)
        {
            if (dependencyObject == null)
                throw FxTrace.Exception.ArgumentNull("dependencyObject");

            dependencyObject.SetValue(PropertyContainer.OwningPropertyContainerProperty, value);
        }