public static void ClearLocalValues(FrameworkElement itemsPresenter, Popup popup)
 {
     if (itemsPresenter != null)
     {
         itemsPresenter.ClearValue(FrameworkElement.HeightProperty);
         itemsPresenter.ClearValue(FrameworkElement.WidthProperty);
     }
     if (popup != null)
     {
         popup.ClearValue(Popup.PlacementProperty);
         popup.ClearValue(Popup.VerticalOffsetProperty);
         popup.ClearValue(Popup.HorizontalOffsetProperty);
     }
 }
    internal void UpdateProperty( FrameworkElement element, DependencyProperty elementProp, DependencyProperty definitionProperty )
    {
      object currentValue = this.GetValue( definitionProperty );
      object localValue = this.ReadLocalValue( definitionProperty );
      object elementValue = element.GetValue( elementProp );
      bool areEquals = false;

      // Avoid setting values if it does not affect anything 
      // because setting a local value may prevent a style setter from being active.
      if( localValue != DependencyProperty.UnsetValue )
      {
        if( ( elementValue != null ) && ( currentValue != null ) )
        {
          areEquals = ( elementValue.GetType().IsValueType && currentValue.GetType().IsValueType )
                      ? elementValue.Equals( currentValue )  // Value Types
                      : currentValue == element.GetValue( elementProp ); // Reference Types
        }

        if( !areEquals )
        {
          element.SetValue( elementProp, currentValue );
        }
        else
        {
          element.ClearValue( elementProp );
        }
      }
    }
Example #3
0
 /// <summary>Captures a snapshot of the source element as a bitmap image. The snapshot is created based on the specified rendering parameters.</summary>
 /// <param name="sourceElement">The source element.</param>
 /// <param name="bitmapSize">The bitmap size.</param>
 /// <param name="scalingMode">The bitmap scaling mode.</param>
 /// <param name="bitmapDpi">The bitmap dpi.</param>
 /// <param name="pixelFormat">The bitmap pixel format.</param>
 /// <returns>The snapshot of the source element.</returns>
 public static BitmapSource CaptureSnapshot(FrameworkElement sourceElement, Size bitmapSize, BitmapScalingMode scalingMode, Vector bitmapDpi, PixelFormat pixelFormat) {
    if (sourceElement == null || bitmapSize.IsZero()) return null;
    var snapshot = new RenderTargetBitmap((int)bitmapSize.Width, (int)bitmapSize.Height, bitmapDpi.X, bitmapDpi.Y, pixelFormat);
    sourceElement.SetValue(RenderOptions.BitmapScalingModeProperty, scalingMode);
    snapshot.Render(sourceElement);
    sourceElement.ClearValue(RenderOptions.BitmapScalingModeProperty);
    snapshot.Freeze();
    return snapshot;
 }
 internal void UpdateProperty( FrameworkElement element, DependencyProperty elementProp, DependencyProperty definitionProperty )
 {
     object currentValue = this.GetValue( definitionProperty );
       object localValue = this.ReadLocalValue( definitionProperty );
       // Avoid setting values if it does not affect anything
       // because setting a local value may prevent a style setter from being active.
       if( ( localValue != DependencyProperty.UnsetValue )
     || currentValue != element.GetValue( elementProp ) )
       {
     element.SetValue( elementProp, currentValue );
       }
       else
       {
     element.ClearValue( elementProp );
       }
 }
Example #5
0
        public void Clean(FrameworkElement target, BaseValueSource valueSource)
        {
            if (Property == null)
            {
                throw new Granular.Exception("Setter.Property cannot be null");
            }

            FrameworkElement   resolvedTarget      = GetResolvedTarget(target, TargetName, valueSource);
            DependencyProperty resolvedProperty    = Property.GetDependencyProperty(resolvedTarget.GetType());
            BaseValueSource    resolvedValueSource = GetResolvedValueSource(valueSource, resolvedTarget);

            if (IsStyleValueSource(valueSource))
            {
                resolvedTarget.ClearValue(resolvedProperty, resolvedValueSource);
            }
            else
            {
                GetInitializedValueOverlapExpression(resolvedTarget, resolvedProperty, resolvedValueSource).ClearValue(this);
            }
        }
Example #6
0
 private static void ValidationIcon_Changed (FrameworkElement control, DpChangedEventArgs<FrameworkElement> args)
 {
     if (args.OldValue != null) {
         control.SizeChanged -= UpdatePopup;
         control.GotKeyboardFocus -= UpdatePopup;
         control.LostKeyboardFocus -= UpdatePopup;
         if (control is TextBoxBase)
             ((TextBox)control).TextChanged -= UpdatePopup;
         control.ClearValue(Validation.ErrorTemplateProperty);
     }
     if (args.NewValue != null) {
         GetOrCreateTooltipPopup(control);
         control.SizeChanged += UpdatePopup;
         control.GotKeyboardFocus += UpdatePopup;
         control.LostKeyboardFocus += UpdatePopup;
         if (control is TextBoxBase)
             ((TextBox)control).TextChanged += UpdatePopup;
         control.SetValue(Validation.ErrorTemplateProperty, null);
     }
     UpdatePopup(control, EventArgs.Empty);
 }
 private static void DetachBehavior(FrameworkElement element)
 {
     var behavior = GetBehavior(element);
     behavior.Detach(element);
     element.ClearValue(BehaviorProperty);
 }
Example #8
0
 private static void UnWireCommand(FrameworkElement element, ICommand oldValue)
 {
     var state = GetCommandState(element);
     if (oldValue == null)
     {
         Debug.Assert(state == null);
     }
     else
     {
         Debug.Assert(state != null);
         state._owner.MouseLeftButtonDown -= source_MouseLeftButtonDown;
         oldValue.CanExecuteChanged -= state.Command_CanExecuteChanged;
         element.ClearValue(CommandStateProperty);
     }
 }
Example #9
0
		private void ClearModel (FrameworkElement elt, object item)
		{
			ModelUIElement3D model = elt.GetValue(LinkedModelProperty) as ModelUIElement3D;
			_modelContainer.Children.Remove(model);

			// Update the positions of all model items
			int removed = (int) model.GetValue(LinkedElementPositionProperty);
			foreach (Visual3D m in _modelContainer.Children) {
				int val = (int) m.GetValue(LinkedElementPositionProperty);
				if (val > removed) {
					m.SetValue(LinkedElementPositionProperty, val - 1);
				}
			}

			model.ClearValue(LinkedElementProperty);
			elt.ClearValue(LinkedModelProperty);

			// Update SelectedIndex if needed
			if (SelectedIndex >= 0 && SelectedIndex < Items.Count) 
			{
				ReflowItems();
			}
			else 
			{
				SelectedIndex = Math.Max(0, Math.Min(SelectedIndex, Items.Count - 1));
			}
		}
    private static bool SetFixedTranslateTransformCore( FrameworkElement element, bool canScrollHorizontally )
    {
      Debug.Assert( element != null );

      var parentScrollViewer = TableViewScrollViewer.GetParentScrollViewer( element ) as ScrollViewer;
      if( parentScrollViewer == null )
        return false;

      var fixedTransform = TableViewScrollViewer.GetStoredFixedTransform( parentScrollViewer );
      Debug.Assert( fixedTransform != null );

      if( canScrollHorizontally )
      {
        if( element.RenderTransform == fixedTransform )
        {
          element.ClearValue( UIElement.RenderTransformProperty );
        }
      }
      else
      {
        element.RenderTransform = fixedTransform;
      }

      return true;
    }
Example #11
0
		private void ClearModel(FrameworkElement elt, object item)
		{
			ModelUIElement3D model = elt.GetValue(LinkedModelProperty) as ModelUIElement3D;
			_modelContainer.Children.Remove(model);

			model.ClearValue(LinkedElementProperty);
			elt.ClearValue(LinkedModelProperty);

			// Update SelectedIndex if needed
			if (SelectedIndex >= 0 && SelectedIndex < Items.Count)
			{
				ReflowItems();
			}
			else
			{
				SelectedIndex = Math.Max(0, Math.Min(SelectedIndex, Items.Count - 1));
			}
		}
        private static void BindActiveMarker(FrameworkElement d)
        {
            IMarkerSelector selector = GetSelector(d);

            if (selector == null)
            {
                d.ClearValue(ActiveMarkerProperty);
            }
            else
            {
                d.SetBinding(ActiveMarkerProperty, new System.Windows.Data.Binding("ActiveMarker") { Source = selector });
            }
        }
 public void ClearContainerForItem(object item, FrameworkElement container)
 {
     container.ClearValue(ItemForItemContainerProperty);
     Containers.Remove(item);
 }