ClearValue() public method

public ClearValue ( DependencyProperty dp ) : void
dp DependencyProperty
return void
Example #1
0
 public static void RebindInactiveBindings(DependencyObject dependencyObject)
 {
     foreach (PropertyDescriptor property in TypeDescriptor.GetProperties(dependencyObject.GetType()))
     {
         var dpd = DependencyPropertyDescriptor.FromProperty(property);
         if (dpd != null)
         {
             var binding = BindingOperations.GetBindingExpressionBase(dependencyObject, dpd.DependencyProperty);
             if (binding != null)
             {
                 //if (property.Name == "DataContext" || binding.HasError || binding.Status != BindingStatus.Active)
                 {
                     // Ensure that no pending calls are in the dispatcher queue
                     Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.SystemIdle, (Action) delegate
                     {
                         // Remove and add the binding to re-trigger the binding error
                         dependencyObject.ClearValue(dpd.DependencyProperty);
                         BindingOperations.SetBinding(dependencyObject, dpd.DependencyProperty,
                             binding.ParentBindingBase);
                     });
                 }
             }
         }
     }
 }
Example #2
0
 private static void OnAttachChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
 {
     Action<System.Windows.Interactivity.TriggerBase> action = null;
     System.Windows.Interactivity.TriggerCollection allTriggers;
     if (e.NewValue != e.OldValue)
     {
         System.Windows.Interactivity.TriggerBase[] enumerable = (System.Windows.Interactivity.TriggerBase[]) d.GetValue(MessageTriggersProperty);
         allTriggers = Interaction.GetTriggers(d);
         if (enumerable != null)
         {
             if (action == null)
             {
                 action = (Action<System.Windows.Interactivity.TriggerBase>) (x => allTriggers.Remove(x));
             }
             enumerable.Apply<System.Windows.Interactivity.TriggerBase>(action);
         }
         System.Windows.Interactivity.TriggerBase[] baseArray2 = Parser.Parse(d, e.NewValue as string).ToArray<System.Windows.Interactivity.TriggerBase>();
         baseArray2.Apply<System.Windows.Interactivity.TriggerBase>(new Action<System.Windows.Interactivity.TriggerBase>(allTriggers.Add));
         if (baseArray2.Length > 0)
         {
             d.SetValue(MessageTriggersProperty, baseArray2);
         }
         else
         {
             d.ClearValue(MessageTriggersProperty);
         }
     }
 }
 private static void TargetPropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
 {
     if (e.NewValue == null)
         d.ClearValue(Storyboard.TargetPropertyProperty);
     else
         Storyboard.SetTargetProperty((Timeline)d, new System.Windows.PropertyPath((DependencyProperty)e.NewValue));
 }
Example #4
0
        /// <summary>
        /// Clears a binding. This method implements the ClearBinding for both WPF and Silverlight.
        /// </summary>
        /// <param name="dependencyObject">The dependency object.</param>
        /// <param name="dependencyProperty">The dependency property.</param>
        public static void ClearBinding(DependencyObject dependencyObject, DependencyProperty dependencyProperty)
        {
#if NET
            BindingOperations.ClearBinding(dependencyObject, dependencyProperty);
#else
            // Other platforms do not support ClearBinding, then we use ClearValue
            dependencyObject.ClearValue(dependencyProperty);
#endif
        }
		private void UpdateBehavior(DependencyObject host, IBehavior behavior)
		{
			if(behavior.IsApplicable())
			{
				behavior.Update();
			}
			else
			{
				host.ClearValue(_property);

				behavior.Detach();
			}
		}
 private static void OnScopeForChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
 {
     if (((InputTypeCollection)e.NewValue)?.IsInputType(d) == true)
     {
         if (GetErrors(d) == null)
         {
             SetErrors(d, ErrorNode.CreateFor(d));
         }
     }
     else if (((InputTypeCollection)e.OldValue)?.IsInputType(d) == true)
     {
         d.ClearValue(ErrorsPropertyKey);
     }
 }
Example #7
0
  private static void OnToolTipChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
  {
    // clean up any old tooltip value
    if (null != e.OldValue)
    {
      var oldTT = d.GetValue(ToolTipService.ToolTipProperty) as ToolTip;

      // detach our tooltip value from the object
      d.ClearValue(ToolTipService.ToolTipProperty);

      if (null != oldTT)
      {
        NameScope.SetNameScope(oldTT, null);

        if (oldTT.Tag == AutoGeneratedId)
          oldTT.Content = null;

        oldTT.Initialized -= NewTTInitialized;
      }
    }

    // if we're getting a new tooltip then initialize the tooltip
    // property of the associated object
    if (null == e.NewValue) return;
    var newTT = e.NewValue as ToolTip ?? new ToolTip {Tag = AutoGeneratedId, Content = e.NewValue};

    // if the value isn't a tooltip then create one around it
    // so we can bind the datacontext and provide a namescope

    d.SetValue(ToolTipService.ToolTipProperty, newTT);

    // provide a temporary namescope so we can handle any element name bindings
    NameScope.SetNameScope(newTT, new NameScopeHelper(d));

    // during the BamlRecordReader's PushContext, the tooltip didn't have
    // a namescope so we need to make sure we remove the namescope before
    // the PopContext or else the reader will try to push too much off
    // the stack and an exception will occur. the Initialized event of
    // the associated element is sufficient to do this. an alternative
    // approach would be to use a custom tooltip that implements INameScope
    // so that the tooltip always has a namescope at the Push and PopContext
    // points.
    newTT.Initialized += NewTTInitialized;
  }
 static void CreateHandler(DependencyObject element, DependencyProperty property)
 {
     var focusMover = element.GetValue(FrameworkElement.DataContextProperty) as IFocusMover;
     if (focusMover == null)
     {
         var handler = element.GetValue(MoveFocusSinkProperty) as MoveFocusSink;
         if (handler != null)
         {
             handler.ReleaseReferences();
             element.ClearValue(MoveFocusSinkProperty);
         }
     }
     else
     {
         var handler = new MoveFocusSink(element as UIElement, property);
         focusMover.MoveFocus += handler.HandleMoveFocus;
         element.SetValue(MoveFocusSinkProperty, handler);
     }
 }
        /// <summary>
        /// Remove the loaded callback from the MediaContext queue
        /// </summary>
        internal static void RemoveLoadedCallback(DependencyObject d, object[] loadedPending)
        {
            Debug.Assert(d is FrameworkElement || d is FrameworkContentElement);

            if (loadedPending != null)
            {
                Debug.Assert(loadedPending.Length == 3);

                // Clear the LoadedPending property
                d.ClearValue(FrameworkElement.LoadedPendingPropertyKey);

                // If the dispatcher operation is pending abort it
                DispatcherOperation operation = (DispatcherOperation)loadedPending[1];
                if (operation.Status == DispatcherOperationStatus.Pending)
                {
                    operation.Abort();
                }

                // Remove the pending loaded information from the MediaContext's pending
                // LoadedOrUnloadedCallbacks list
                MediaContext.From(d.Dispatcher).RemoveLoadedOrUnloadedCallback((LoadedOrUnloadedOperation)loadedPending[0]);
            }
        }
Example #10
0
        private static void AnimateProperty(DependencyObject target, DependencyProperty property, DoubleAnimation animation, EventHandler animationDone)
        {
            if (IsAnimationEnabled)
            {
                ((IAnimatable)target).BeginAnimation(property, animation);
            }
            else
            {
                ((IAnimatable)target).BeginAnimation(property, null);
                if (animation.To != null)
                {
                    target.SetValue(property, animation.To);
                }
                else
                {
                    target.ClearValue(property);
                }

                if (animationDone != null)
                {
                    animationDone(target, EventArgs.Empty);
                }
            }
        }
Example #11
0
 private static void ClearOriginalValue(DependencyObject obj)
 {
     obj.ClearValue(OriginalValueProperty);
 }
Example #12
0
        public static void SetKinectRegion(DependencyObject obj, KinectRegion value)
        {
            if (obj == null)
            {
                throw new ArgumentNullException("obj");
            }

            if (value == null)
            {
                obj.ClearValue(KinectRegionProperty);
            }
            else
            {
                obj.SetValue(KinectRegionProperty, value);
            }
        }
Example #13
0
 private static void SynchronizeValue(DependencyProperty dp, DependencyObject parent, DependencyObject child)
 { 
     if (IsDefaultValue(dp, parent))
     { 
         child.ClearValue(dp); 
     }
     else 
     {
         object value = parent.GetValue(dp);
         child.SetValue(dp, value);
     } 
 }
Example #14
0
 internal static void ClearPseudoInheritedProperties(DependencyObject child)
 {
     if (child != null)
     {
         child.ClearValue(RibbonControlService.IsInQuickAccessToolBarPropertyKey);
         child.ClearValue(RibbonControlService.IsInControlGroupPropertyKey);
         child.ClearValue(RibbonControlService.ControlSizeDefinitionProperty);
     }
 }
 public static void ClearAdditional(DependencyObject dependencyObject)
 {
     if (dependencyObject != null)
     {
         dependencyObject.ClearValue (AdditionalProperty);
     }
 }
Example #16
0
        // Update HasErrors and Invalidate the public ValidationErrors property whose GetOverride will return
        // the updated value of ValidationErrorsInternal, nicely wrapped into a ReadOnlyCollection<T> 
        private static void OnErrorsInternalChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            ValidationErrorCollection newErrors = e.NewValue as ValidationErrorCollection;
 
            if (newErrors != null)
            { 
                d.SetValue(ErrorsPropertyKey, new ReadOnlyObservableCollection<ValidationError>(newErrors)); 
            }
            else 
            {
                d.ClearValue(ErrorsPropertyKey);
            }
        } 
Example #17
0
        // remove a validation error from the given element
        internal static void RemoveValidationError(ValidationError validationError, DependencyObject targetElement, bool shouldRaiseEvent) 
        {
            if (targetElement == null) 
                return; 

            ValidationErrorCollection validationErrors = GetErrorsInternal(targetElement); 
            if (validationErrors == null || validationErrors.Count == 0 || !validationErrors.Contains(validationError))
                return;

            bool isValid = (validationErrors.Count == 1);   // about to remove the last error 

            if (isValid) 
            { 
                // instead of removing the last error, just discard the error collection.
                // This sends out only one property-change event, instead of two. 
                // Any bindings to Errors[x] will appreciate the economy.
                targetElement.ClearValue(HasErrorPropertyKey);

                targetElement.ClearValue(ValidationErrorsInternalProperty); 

                if (shouldRaiseEvent) 
                { 
                    OnValidationError(targetElement, validationError, ValidationErrorEventAction.Removed);
                } 

                ShowValidationAdorner(targetElement, false);
            }
            else 
            {
                // if it's not the last error, just remove it. 
                validationErrors.Remove(validationError); 

                if (shouldRaiseEvent) 
                {
                    OnValidationError(targetElement, validationError, ValidationErrorEventAction.Removed);
                }
            } 
        }
Example #18
0
        /// <summary>
        /// Remove data Binding (if any) from a property. 
        /// </summary>
        /// <remarks>
        /// If the given property is data-bound, via a Binding, PriorityBinding or MultiBinding,
        /// the BindingExpression is removed, and the property's value changes to what it 
        /// would be as if no local value had ever been set.
        /// If the given property is not data-bound, this method has no effect. 
        /// </remarks> 
        /// <param name="target">object from which to remove Binding</param>
        /// <param name="dp">property from which to remove Binding</param> 
        /// <exception cref="ArgumentNullException"> target and dp cannot be null </exception>
        public static void ClearBinding(DependencyObject target, DependencyProperty dp)
        {
            if (target == null) 
                throw new ArgumentNullException("target");
            if (dp == null) 
                throw new ArgumentNullException("dp"); 
//            target.VerifyAccess();
 
            if (IsDataBound(target, dp))
                target.ClearValue(dp);
        }
Example #19
0
 private static void RemoveElementFromWatchList(DependencyObject element)
 {
     if(_watchers.Remove(element))
     {
         element.ClearValue(CachedSourceProperty);
         element.ClearValue(GetsSourceChangedEventProperty);
     }
 }
Example #20
0
        /// <summary>
        /// Remove all data Binding (if any) from a DependencyObject. 
        /// </summary> 
        /// <param name="target">object from which to remove bindings</param>
        /// <exception cref="ArgumentNullException"> DependencyObject target cannot be null </exception> 
        public static void ClearAllBindings(DependencyObject target)
        {
            if (target == null)
                throw new ArgumentNullException("target"); 
//            target.VerifyAccess();
 
            LocalValueEnumerator lve = target.GetLocalValueEnumerator(); 

            // Batch properties that have BindingExpressions since clearing 
            // during a local value enumeration is illegal
            ArrayList batch = new ArrayList(8);

            while (lve.MoveNext()) 
            {
                LocalValueEntry entry = lve.Current; 
                if (IsDataBound(target, entry.Property)) 
                {
                    batch.Add(entry.Property); 
                }
            }

            // Clear all properties that are storing BindingExpressions 
            for (int i = 0; i < batch.Count; i++)
            { 
                target.ClearValue((DependencyProperty)batch[i]); 
            }
        } 
Example #21
0
        private static void OnAttachChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            if(e.NewValue == e.OldValue)
                return;

            var messageTriggers = (System.Windows.Interactivity.TriggerBase[])d.GetValue(MessageTriggersProperty);
            var allTriggers = Interaction.GetTriggers(d);

            if(messageTriggers != null)
                messageTriggers.Apply(x => allTriggers.Remove(x));

            var newTriggers = Parser.Parse(d, e.NewValue as string).ToArray();
            newTriggers.Apply(allTriggers.Add);

            if(newTriggers.Length > 0)
                d.SetValue(MessageTriggersProperty, newTriggers);
            else d.ClearValue(MessageTriggersProperty);
        }
        private void FirePropertyChangeInAncestry(DependencyObject element,
            bool oldValue,
            DeferredElementTreeState treeState,
            Action<DependencyObject, bool> originChangedAction)
        {
            UIElement uie;
            ContentElement ce;
            UIElement3D uie3D;
            CastElement(element, out uie, out ce, out uie3D);

            bool flagChanged = IsFlagSet(uie, ce, uie3D, FlagChanged);
            bool isFlagOldOriginCacheSet = ((FlagOldOriginCache == CoreFlags.None) ? false : IsFlagSet(uie, ce, uie3D, FlagOldOriginCache));
            bool isFlagNewOriginCacheSet = ((FlagNewOriginCache == CoreFlags.None) ? false : IsFlagSet(uie, ce, uie3D, FlagNewOriginCache));

            if (flagChanged || isFlagOldOriginCacheSet || isFlagNewOriginCacheSet)
            {
                if (flagChanged)
                {
                    // if FlagChanged bit is set, then the value has changed effectively
                    // after considering all the origins. Hence change the property value
                    // and fire notifications.
                    SetFlag(uie, ce, uie3D, FlagChanged, false);

                    if (oldValue)
                    {
                        element.ClearValue(FlagKey);
                    }
                    else
                    {
                        element.SetValue(FlagKey, true);
                    }

                    FireNotifications(uie, ce, uie3D, oldValue);
                }

                if (isFlagOldOriginCacheSet || isFlagNewOriginCacheSet)
                {
                    SetFlag(uie, ce, uie3D, FlagOldOriginCache, false);
                    SetFlag(uie, ce, uie3D, FlagNewOriginCache, false);
                    if (isFlagOldOriginCacheSet != isFlagNewOriginCacheSet)
                    {
                        // if either FlagOldOriginCache or FlagNewOriginCache
                        // are set, then the origin change has affected this node
                        // and hence originChangedAction should be executed.
                        Debug.Assert(originChangedAction != null);
                        originChangedAction(element, oldValue);
                    }
                }

                // Check for block reverse inheritance flag, elements like popup want to set this.
                if (BlockReverseInheritance(uie, ce, uie3D))
                {
                    return;
                }

                // Call FirePropertyChange up the visual and logical trees.
                // Note our minimal optimization check to avoid walking both
                // the core and logical parents if they are the same.
                {
                    DependencyObject coreParent = DeferredElementTreeState.GetInputElementParent(element, treeState);
                    DependencyObject logicalParent = DeferredElementTreeState.GetLogicalParent(element, treeState);

                    if (coreParent != null)
                    {
                        FirePropertyChangeInAncestry(coreParent, oldValue, treeState, originChangedAction);
                    }
                    if (logicalParent != null && logicalParent != coreParent)
                    {
                        FirePropertyChangeInAncestry(logicalParent, oldValue, treeState, originChangedAction);
                    }
                }
            }
        }
Example #23
0
 private static void RestoreValue(DependencyObject d, DependencyProperty property, ValueAndValueSource v)
 {
     Debug.Assert(d != null);
     Debug.Assert(property != null);
     Debug.Assert(v != null);
     if (v.ValueSource == BaseValueSource.Local)
     {
         d.SetValue(property, v.Value);
     }
     else
     {
         d.ClearValue(property);
         d.CoerceValue(property);
     }
 }
Example #24
0
 internal static void ClearColumnReorderingDragSourceManager( DependencyObject obj )
 {
   obj.ClearValue( TableflowView.ColumnReorderingDragSourceManagerProperty );
 }
    private void RemoveContainer( DependencyObject container, object dataItem )
    {
      m_dataGridControl.ClearItemContainer( container, dataItem );

      if( this.IsRecyclingEnabled )
      {
        this.EnqueueContainer( container, dataItem );

        CustomItemContainerGenerator.SetDataItemProperty( container, CustomItemContainerGenerator.NotSet );
        if( GroupLevelIndicatorPane.GetGroupLevel( container ) == -1 )
        {
          container.ClearValue( GroupLevelIndicatorPane.GroupLevelProperty );
        }

        if( container is HeaderFooterItem )
        {
          container.ClearValue( DataGridControl.StatContextPropertyKey );
        }
      }
    }
Example #26
0
 internal static void ClearIsBeingDraggedAnimated( DependencyObject obj )
 {
   obj.ClearValue( TableflowView.IsBeingDraggedAnimatedProperty );
 }
Example #27
0
        public static void SetIsPrimaryHandPointerOver(DependencyObject obj, bool value)
        {
            if (obj == null)
            {
                throw new ArgumentNullException("obj");
            }

            if (!value)
            {
                obj.ClearValue(IsPrimaryHandPointerOverProperty);
            }
            else
            {
                obj.SetValue(IsPrimaryHandPointerOverProperty, true);
            }
        }
        /// <summary>
        /// Detaches an undo service from the given FrameworkElement.
        /// </summary>
        /// <param name="scope">
        /// A FrameworkElement with UndoManager attached to it.
        /// </param>
        /// <remarks>
        /// Throws an exception if the scope does not have undo service attached to it.
        /// </remarks>
        internal static void DetachUndoManager(DependencyObject scope)
        {
            UndoManager undoManager;

            if (scope == null)
            {
                throw new ArgumentNullException("scope");
            }

            // Detach existing undo service if any
            undoManager = scope.ReadLocalValue(UndoManager.UndoManagerInstanceProperty) as UndoManager;
            if (undoManager != null)
            {
                // Disable the service while in detached state
                undoManager.IsEnabled = false;

                // Remove the service from a tre
                scope.ClearValue(UndoManager.UndoManagerInstanceProperty);

                // Break the linkage to its scope
                if (undoManager is UndoManager)
                {
                    Debug.Assert(((UndoManager)undoManager)._scope == scope);
                    ((UndoManager)undoManager)._scope = null;
                }
            }
        }
 private void PersistAttachedItemValue(DependencyObject objectWithProperty, DependencyProperty property)
 {
     ValueSource valueSource = DependencyPropertyHelper.GetValueSource(objectWithProperty, property);
     if (valueSource.BaseValueSource == BaseValueSource.Local)
     {
         // attach the local value to the item so it can be restored later.
         _owner.ItemAttachedStorage.SetValue(Item, property, objectWithProperty.GetValue(property));
         objectWithProperty.ClearValue(property);
     }
 }
Example #30
0
        //-------------------------------------------------------------------
        // 
        //  Internal Methods
        //
        //--------------------------------------------------------------------
 
        #region Internal Methods
 
        /// <summary> 
        /// Clear the IsSelected property from containers that are no longer used.  This is done for container recycling;
        /// If we ever reuse a container with a stale IsSelected value the UI will incorrectly display it as selected. 
        /// </summary>
        protected override void ClearContainerForItemOverride(DependencyObject element, object item)
        {
            base.ClearContainerForItemOverride(element, item); 

            //This check ensures that selection is cleared only when the element is getting recycled. 
            if ( !((IGeneratorHost)this).IsItemItsOwnContainer(item) ) 
            {
                element.ClearValue(IsSelectedProperty); 
            }
        }