/// <summary> /// Writes the attached property Dock to the given element. /// </summary> /// <param name="element">UIElement to which to write the attached property.</param> /// <param name="dock">The property value to set</param> /// <seealso cref="DockPanel.DockProperty" /> public static void SetDock(UIElement element, Dock dock) { if (element == null) { throw new ArgumentNullException("element"); } element.SetValue(DockProperty, dock); }
/// <summary> /// Writes the attached property Left to the given element. /// </summary> /// <param name="element">The element to which to write the Left attached property.</param> /// <param name="length">The length to set</param> /// <seealso cref="Canvas.LeftProperty" /> public static void SetLeft(UIElement element, double length) { if (element == null) { throw new ArgumentNullException("element"); } element.SetValue(LeftProperty, length); }
/* private static void PositiveValueValidation(DependencyObject d, DependencyPropertyChangedEventArgs e) { if ((int)e.NewValue <= 0) { throw new ArgumentException(Resource.ToolTipService_SetTimeoutProperty_InvalidValue, "e"); } } */ private static void RegisterToolTip(UIElement owner, object toolTip) { Debug.Assert(owner != null, "ToolTip must have an owner"); Debug.Assert(toolTip != null, "ToolTip can not be null"); owner.MouseEnter += new MouseEventHandler(OnOwnerMouseEnter); owner.MouseLeave += new MouseEventHandler(OnOwnerMouseLeave); owner.MouseLeftButtonDown += new MouseButtonEventHandler(OnOwnerMouseLeftButtonDown); owner.KeyDown += new KeyEventHandler(OnOwnerKeyDown); owner.SetValue (AssignedToolTipProperty, ConvertToToolTip(toolTip)); }
private void SetItemsHostInsetForChild(int index, UIElement child, IContainItemStorage itemStorageProvider, bool isHorizontal) { Debug.Assert(!IsVSP45Compat, "SetItemsHostInset should not be called in VSP45-compat mode"); // this only applies to a hierarchical element with a visible ItemsHost bool isChildHorizontal = isHorizontal; IHierarchicalVirtualizationAndScrollInfo virtualizingChild = GetVirtualizingChild(child, ref isChildHorizontal); Panel itemsHost = (virtualizingChild == null) ? null : virtualizingChild.ItemsHost; if (itemsHost == null || !itemsHost.IsVisible) return; // get the transformation from child coords to itemsHost coords GeneralTransform transform = child.TransformToDescendant(itemsHost); if (transform == null) return; // when transform is undefined, ItemsHost is effectively invisible // build a rect (in child coords) describing the child's extended frame FrameworkElement fe = virtualizingChild as FrameworkElement; Thickness margin = (fe == null) ? new Thickness() : fe.Margin; Rect childRect = new Rect(new Point(), child.DesiredSize); childRect.Offset(-margin.Left, -margin.Top); // transform to itemsHost coords Rect itemsRect = transform.TransformBounds(childRect); // compute the desired inset, avoiding catastrophic cancellation errors Size itemsSize = itemsHost.DesiredSize; double left = DoubleUtil.AreClose(0, itemsRect.Left) ? 0 : -itemsRect.Left; double top = DoubleUtil.AreClose(0, itemsRect.Top) ? 0 : -itemsRect.Top; double right = DoubleUtil.AreClose(itemsSize.Width, itemsRect.Right) ? 0 : itemsRect.Right-itemsSize.Width; double bottom = DoubleUtil.AreClose(itemsSize.Height, itemsRect.Bottom) ? 0 : itemsRect.Bottom-itemsSize.Height; Thickness inset = new Thickness(left, top, right, bottom); // get the item to use as the key into items storage object item = GetItemFromContainer(child); if (item == DependencyProperty.UnsetValue) { Debug.Assert(false, "SetInset should only be called for a container"); return; } // see whether inset is changing object box = itemStorageProvider.ReadItemValue(item, ItemsHostInsetProperty); bool changed = (box == null); bool remeasure = changed; if (!changed) { Thickness oldInset = (Thickness)box; changed = !( DoubleUtil.AreClose(oldInset.Left, inset.Left) && DoubleUtil.AreClose(oldInset.Top, inset.Top ) && DoubleUtil.AreClose(oldInset.Right, inset.Right) && DoubleUtil.AreClose(oldInset.Bottom, inset.Bottom) ); // only changes along the scrolling axis require a remeasure. // use a less stringent "AreClose" test; experiments show that the // trailing inset can change due to roundoff error by an amount // that is larger than the tolerance in DoubleUtil, but not large // enough to warrant an expensive remeasure. remeasure = changed && ( (isHorizontal && !(AreInsetsClose(oldInset.Left, inset.Left) && AreInsetsClose(oldInset.Right, inset.Right))) || (!isHorizontal && !(AreInsetsClose(oldInset.Top, inset.Top) && AreInsetsClose(oldInset.Bottom, inset.Bottom))) ); } if (changed) { // store the new inset itemStorageProvider.StoreItemValue(item, ItemsHostInsetProperty, inset); child.SetValue(ItemsHostInsetProperty, inset); } if (remeasure) { // re-measure the scrolling panel ItemsControl scrollingItemsControl = GetScrollingItemsControl(child); Panel scrollingPanel = (scrollingItemsControl == null) ? null : scrollingItemsControl.ItemsHost; if (scrollingPanel != null) { VirtualizingStackPanel vsp = scrollingPanel as VirtualizingStackPanel; if (vsp != null) { vsp.AnchoredInvalidateMeasure(); } else { scrollingPanel.InvalidateMeasure(); } } } }
/// <summary> /// Helper for setting ZIndex property on a UIElement. /// </summary> /// <param name="element">UIElement to set ZIndex property on.</param> /// <param name="value">ZIndex property value.</param> public static void SetZIndex(UIElement element, int value) { if (element == null) { throw new ArgumentNullException("element"); } element.SetValue(ZIndexProperty, value); }
public static void SetTop (UIElement ctrl, float value) { ctrl.SetValue (TopProperty, value); }
public static void SetLeft ( UIElement ctrl, float value ) { ctrl.SetValue (LeftProperty, value); }
public static void SetColumnSpan (UIElement item, int columnSpan) { item.SetValue (ColumnSpanProperty, columnSpan); }
public static void SetRowSpan (UIElement item, int rowSpan) { item.SetValue (RowSpanProperty, rowSpan); }
public static void SetRow (UIElement item, int row) { item.SetValue (RowProperty, row); }