public void Remove(Adorner adorner) { RemoveVisualChild(adorner); RemoveLogicalChild(adorner); adornersBounds.Remove(adorner); }
private static void HideFocusVisual() { if (currentFocusVisual != null) { ((AdornerLayer)currentFocusVisual.VisualParent).Remove(currentFocusVisual); currentFocusVisual = null; } }
public void Add(Adorner adorner) { AddLogicalChild(adorner); AddVisualChild(adorner); adornersBounds.Add(adorner, GetAdornerBounds(adorner)); InvalidateArrange(); }
private void UpdateTranslation(bool scrollNow) { SceneView activeView = this.ActiveView; SceneViewModel viewModel = activeView.ViewModel; if (!this.HasMouseMovedAfterDown) { this.hasInitializedBrush = false; } SceneElement primarySelection = this.ActiveView.ElementSelectionSet.PrimarySelection; if (primarySelection == null) { return; } PropertyReference propertyReference = this.GetBrushPropertyReference((SceneNode)primarySelection); if (propertyReference == null || Adorner.NonAffineTransformInParentStack(primarySelection)) { return; } this.EnsureEditTransaction(); if (!this.hasInitializedBrush) { if (!PlatformTypes.IsInstance(this.ActiveView.ElementSelectionSet.PrimarySelection.GetComputedValue(propertyReference), PlatformTypes.GradientBrush, (ITypeResolver)primarySelection.ProjectContext)) { object lastUsed = BrushCategory.GetLastUsed(this.ActiveView.DesignerContext, this.ActiveView.Document.DocumentContext, BrushCategory.Gradient); this.ActiveView.ElementSelectionSet.PrimarySelection.SetValueAsWpf(propertyReference, lastUsed); this.UpdateEditTransaction(); } this.CopyPrimaryBrushToSelection(); this.hasInitializedBrush = true; } object computedValue = primarySelection.GetComputedValue(propertyReference); Matrix matrix = activeView.GetComputedTransformFromRoot(primarySelection) * BrushAdorner.GetCompleteInverseBrushTransformMatrix((Base2DElement)primarySelection, computedValue, true); Point point1 = this.dragStartPosition * matrix; Point point2 = this.dragCurrentPosition * matrix; Point point3 = RoundingHelper.RoundPosition(point1); Point point4 = RoundingHelper.RoundPosition(point2); if (PlatformTypes.IsInstance(computedValue, PlatformTypes.LinearGradientBrush, (ITypeResolver)primarySelection.ProjectContext)) { this.SetBrushValue(LinearGradientBrushNode.StartPointProperty, (object)point3); this.SetBrushValue(LinearGradientBrushNode.EndPointProperty, (object)point4); } else if (PlatformTypes.IsInstance(computedValue, PlatformTypes.RadialGradientBrush, (ITypeResolver)primarySelection.ProjectContext)) { this.SetBrushValue(RadialGradientBrushNode.CenterProperty, (object)point3); this.SetBrushValue(RadialGradientBrushNode.GradientOriginProperty, (object)point3); if (this.IsShiftDown) { Vector vector = point4 - point3; this.SetBrushValue(RadialGradientBrushNode.RadiusXProperty, (object)vector.Length); this.SetBrushValue(RadialGradientBrushNode.RadiusYProperty, (object)vector.Length); } else { Point point5 = RoundingHelper.RoundPosition(new Point(Math.Abs(point3.X - point4.X), Math.Abs(point3.Y - point4.Y))); this.SetBrushValue(RadialGradientBrushNode.RadiusXProperty, (object)point5.X); this.SetBrushValue(RadialGradientBrushNode.RadiusYProperty, (object)point5.Y); } } activeView.EnsureVisible(this.dragStartPosition + this.dragCurrentPosition - this.dragStartPosition, scrollNow); this.UpdateEditTransaction(); }
private static void ShowFocusVisual(FrameworkElement element) { HideFocusVisual(); if (element.FocusVisualStyle == null) { return; } currentFocusVisual = new Adorner(element) { Child = new Control { Style = element.FocusVisualStyle } }; AdornerLayer.GetAdornerLayer(element).Add(currentFocusVisual); }
/// <summary> /// Adds <paramref name="adorner"/> to the <see cref="AdornerLayer"/> /// If no adorner layer is present a retry is performed with DispatcherPriority.Loaded /// </summary> /// <param name="adorner">The <see cref="Adorner"/></param> public static void Show(Adorner adorner) { Show(adorner, retry: true); }
public void Insert(int index, Adorner value) {}
public BehaviorServiceAdornerCollection(Adorner[] value) {}
public void AddRange(Adorner[] value) {}
public void CopyTo(Adorner[] array, int index) {}
/// <summary> /// Occurs as the mouse changes position when a Thumb control has logical focus and mouse capture /// </summary> /// <param name="sender">The sender</param> /// <param name="e">The event args</param> private void ResizeDragDelta(object sender, DragDeltaEventArgs e) { // get to resized element Grid thumbsGrid = (Grid)VisualTreeHelper.GetParent(this); Thumb parentThumb = (Thumb)VisualTreeHelper.GetParent(thumbsGrid); Adorner adorner = (Adorner)VisualTreeHelper.GetParent(parentThumb); // presenter that holds dragged item ContentPresenter presenter = (ContentPresenter) VisualTreeHelper.GetParent(adorner.AdornedElement); // parent canvas CustomCanvas canvas = (CustomCanvas) VisualTreeHelper.GetParent(presenter); // prepare items for resize depending on item level (question or bubble) List<ContentPresenter> presenters; if (canvas.Name.Equals(Properties.Resources.RootCanvasName)) { // here we resize questions (e.g. choicebox), so take selected items presenters = ControlHelper.GetSelectedChildPresenters(canvas); } else { // here we resize bubbles, so get neighbor bubbles inside question (always resize bubbles equally) presenters = ControlHelper.GetChildPresenters(canvas); } double minLeft, minTop, minDeltaHorizontal, minDeltaVertical; double maxDeltaVertical, maxDeltaHorizontal; double maxHorizontalDeltaToChild = double.MaxValue; double maxVerticalDeltaToChild = double.MaxValue; this.CalculateLimits(canvas, presenters, out minLeft, out minTop, out minDeltaHorizontal, out minDeltaVertical, out maxDeltaHorizontal, out maxDeltaVertical); minDeltaVertical = Math.Min(minDeltaVertical, maxVerticalDeltaToChild); minDeltaHorizontal = Math.Min(minDeltaHorizontal, maxHorizontalDeltaToChild); foreach (ContentPresenter element in presenters) { double newHeight = element.ActualHeight; double newWidth = element.ActualWidth; double newTop = Canvas.GetTop(element); double newLeft = Canvas.GetLeft(element); double scale, dragDeltaVertical; switch (this.VerticalAlignment) { case VerticalAlignment.Bottom: dragDeltaVertical = Math.Max(Math.Min(-e.VerticalChange, minDeltaVertical), -maxDeltaVertical); newHeight = element.ActualHeight - dragDeltaVertical; break; case VerticalAlignment.Top: dragDeltaVertical = Math.Min(Math.Max(-minTop, e.VerticalChange), minDeltaVertical); scale = (element.ActualHeight - dragDeltaVertical) / element.ActualHeight; newTop = newTop - element.Height * (scale - 1); newHeight = element.ActualHeight - dragDeltaVertical; break; } double dragDeltaHorizontal; switch (this.HorizontalAlignment) { case HorizontalAlignment.Left: dragDeltaHorizontal = Math.Min(Math.Max(-minLeft, e.HorizontalChange), minDeltaHorizontal); scale = (element.ActualWidth - dragDeltaHorizontal) / element.ActualWidth; newLeft = Canvas.GetLeft(element) - element.Width * (scale - 1); newWidth = element.ActualWidth * scale; break; case HorizontalAlignment.Right: dragDeltaHorizontal = Math.Max(Math.Min(-e.HorizontalChange, minDeltaHorizontal), -maxDeltaHorizontal); newWidth = element.ActualWidth - dragDeltaHorizontal; break; } var childs = this.GetChildElements(element); if (childs == null) { element.Width = newWidth; element.Height = newHeight; Canvas.SetTop(element, newTop); Canvas.SetLeft(element, newLeft); } else { double scaleH = newHeight / element.ActualHeight; double scaleW = newWidth / element.ActualWidth; if (this.CanTransformChildsRecursive(childs, scaleH, scaleW)) { this.TransformChildsRecursive(childs, scaleH, scaleW); element.Width = newWidth; element.Height = newHeight; Canvas.SetTop(element, newTop); Canvas.SetLeft(element, newLeft); } } } e.Handled = true; }
public void AddAdornerToImageView(Adorner adorner) { AdornerLayer.GetAdornerLayer(ImageViewScreenshot)?.Add(adorner); }
public static void SetAdornerInstance(DependencyObject element, Adorner value) { element.SetValue(AdornerInstanceProperty, value); }
private static void AddAdorner(UIElement adornedElement, Adorner adorner) { var layer = AdornerLayer.GetAdornerLayer(adornedElement); layer.Add(adorner); }
private static void SetAdorner(this DependencyObject element, Adorner value) { element.SetValue(AdornerProperty, value); }
private void output_OnDragStop(Adorner obj) { this.adornerLayer.Remove(obj); }
/// <summary> /// Removes <paramref name="adorner"/> from the <see cref="AdornerLayer"/> /// </summary> /// <param name="adorner">The <see cref="Adorner"/></param> public static void Remove(Adorner adorner) { var adornerLayer = GetAdornerLayer(adorner.AdornedElement); adornerLayer?.Remove(adorner); }
public void Add(Adorner adorner) { _adornerLayer.Add(adorner); }
private FocusVisualAdorner(FrameworkElement element) { adornerLayer = AdornerLayer.GetAdornerLayer(element); adorner = new Adorner(element) { Child = new Control { Style = element.FocusVisualStyle, Focusable = false } }; adornerLayer.Add(adorner); }
public override void DesignMode() { if (!IsDesignMode) { AdornerLayer = new Adorner(this); AdornerLayer.Selected += OnSelected; } }
internal static void ClearTemplatedAdornerChild(this Adorner adorner) { AssertTemplatedAdornerType(adorner); ClearChildMethod.Invoke(adorner, null); }
public bool Contains(Adorner value) {}
internal static FrameworkElement GetTemplatedAdornerReferenceElement(this Adorner adorner) { AssertTemplatedAdornerType(adorner); return((FrameworkElement)ReferenceElementProperty.GetValue(adorner)); }
public int IndexOf(Adorner value) {}
public static void CancelSelected() { if (null != _lastFocusObject) { _lastFocusObject.SetUnselect(); _lastFocusObject = null; } }
public void Remove(Adorner value) {}
private Rect GetAdornerBounds(Adorner adorner) { return new Rect(PointFromRoot(adorner.AdornedElement.PointToRoot(Point.Zero)), adorner.AdornedElement.VisualSize); }
// Methods public int Add(Adorner value) {}
private void AdornOperationContainer(OperationContainer container, IDictionary <int, int> lineMap, AdornerLayer layer) { foreach (Operation operation in container.Operations) { int ln; if (!lineMap.TryGetValue(operation.Id, out ln)) { continue; } ln -= 1; int ch = GetCharacterIndexFromLineIndex(ln); int len = GetLineLength(ln); var endRect = GetRectFromCharacterIndex(ch + len - 1, true); Adorner adorner = null; if (operation is Loop) { var loop = (Loop)operation; int iteration; if (!this.currentIterations.TryGetValue(loop.Id, out iteration)) { iteration = 0; } var loopadorner = new LoopAdorner(this, loop); if (iteration >= loopadorner.Iterations.Length) { this.currentIterations[loop.Id] = iteration = 0; } loopadorner.CurrentIteration = iteration; loopadorner.IterationChanged += (s, e) => { this.currentIterations[loop.Id] = loopadorner.CurrentIteration; OnMethodCallChanged(); }; adorner = loopadorner; if (loopadorner.Iterations.Length > 0) { AdornOperationContainer(loopadorner.Iterations[iteration], lineMap, layer); } } else if (operation is StateChange) { adorner = new StateChangeAdorner(this, (StateChange)operation); } else if (operation is ReturnValue) { adorner = new ReturnAdorner(this, (ReturnValue)operation); } if (adorner != null) { double delta = endRect.Height - (endRect.Height * 0.8); adorner.Margin = new Thickness(endRect.X + 2, endRect.Y + (delta / 2), 0, 0); adorner.MaxHeight = endRect.Height; this.adorners.Add(operation.Id, adorner); layer.Add(adorner); } } }
internal static void SetTemplatedAdornerReferenceElement(this Adorner adorner, FrameworkElement referenceElement) { AssertTemplatedAdornerType(adorner); ReferenceElementProperty.SetValue(adorner, referenceElement); }
public IAdorneredTooltip Create(Adorner adornered, bool adornerLayerVisibility) { return(new AdorneredTooltip(adornered, adornerLayerVisibility)); }
private void SetSelect() { if (!IsSelected) { IsSelected = true; return; } if (null != _contentAdorner && null != _topLeftAdorner && null != _topRightAdorner && null != _bottomLeftAdorner && null != _bottomLeftAdorner && null != _bottomRightAdorner && null != _topLeftAdorner && null != _topCenterAdorner && null != _centerLeftAdorner && null != _centerRightAdorner && null != _bottomCenterAdorner) { _contentAdorner.Opacity = 1; _topLeftAdorner.Visibility = Visibility.Visible; _topRightAdorner.Visibility = Visibility.Visible; _bottomLeftAdorner.Visibility = Visibility.Visible; _bottomRightAdorner.Visibility = Visibility.Visible; if (!IsLockScale) { _topCenterAdorner.Visibility = Visibility.Visible; _centerLeftAdorner.Visibility = Visibility.Visible; _centerRightAdorner.Visibility = Visibility.Visible; _bottomCenterAdorner.Visibility = Visibility.Visible; } if (_lastFocusObject != this && null != _lastFocusObject) { _lastFocusObject.SetUnselect(); } _lastFocusObject = this; } }
public static void AddMutiSelected(Adorner adorner) { if(!_selectedAdorners.Contains(adorner)) { _selectedAdorners.Add(adorner); adorner.SetMutiSelect(); } }
public static void CancelSelected() { var array = new Adorner[_selectedAdorners.Count]; _selectedAdorners.CopyTo(array); foreach (var a in array) { a.SetMutiUnselect(); if (null != a.Unselected) { a.Unselected(a, EventArgs.Empty); } _selectedAdorners.Remove(a); } array = null; }
public static void RemoveMutiSelected(Adorner adorner) { if (_selectedAdorners.Contains(adorner)) { _selectedAdorners.Remove(adorner); adorner.SetMutiUnselect(); } }
public override void DesignMode() { if (!IsDesignMode) { AdornerLayer = new Adorner(this); AdornerLayer.Selected += OnSelected; var menu = new ContextMenu(); var menuItem = new MenuItem() { Header = "属性" }; menuItem.Click += PropertyMenuItem_Click; menu.Items.Add(menuItem); AdornerLayer.SetValue(ContextMenuService.ContextMenuProperty, menu); } }
private bool UpdateEffects(DragEventArgs e) { if (!this.isDragging) { DragDropRemoveAnyAdorner(); e.Effects = DragDropEffects.None; return(true); } object dragSource = e.Data.GetData(formatName); if (dragSource == null) { DragDropRemoveAnyAdorner(); e.Effects = DragDropEffects.None; return(false); } const int dragScrollMarginSpeedSlow = 30; const int dragScrollMarginFast = 10; Point pt = e.GetPosition(this.mainControl); HitTestResult result = VisualTreeHelper.HitTest(this.mainControl, pt); if (result != null) { if (pt.Y < dragScrollMarginSpeedSlow) { // The user is close to the bottom of the container (ListBox or TreeView) if (pt.Y < dragScrollMarginFast) { AttemptToScrollUp(4); } else { AttemptToScrollUp(1); } } else if (pt.Y > this.mainControl.ActualHeight - dragScrollMarginSpeedSlow) { // The user is close to the bottom of the container (ListBox or TreeView) if (pt.Y > this.mainControl.ActualHeight - dragScrollMarginFast) { AttemptToScrollDown(4); } else { AttemptToScrollDown(1); } } FrameworkElement ctrl = result.VisualHit as FrameworkElement; if (ctrl != null) { DragDropTarget possibleDropTarget = this.calledBackForValidatingTarget(dragSource, ctrl, e.Effects); if (possibleDropTarget != null && possibleDropTarget.DataSource != previousPossibleDropTarget) { if (possibleDropTarget.DataSource != dragSource) { DragDropRemoveAnyAdorner(); previousPossibleDropTarget = possibleDropTarget.DataSource; this.adornerLayer = AdornerLayer.GetAdornerLayer(possibleDropTarget.TargetElement); lastAdornerUsed = new AdornerDropTarget(possibleDropTarget.TargetElement); this.adornerLayer.Add(lastAdornerUsed); } } } else { DragDropRemoveAnyAdorner(); } } else { DragDropRemoveAnyAdorner(); } if (((e.AllowedEffects & DragDropEffects.Copy) == DragDropEffects.Copy) || ((e.AllowedEffects & DragDropEffects.Move) == DragDropEffects.Move)) { if ((e.KeyStates & DragDropKeyStates.ControlKey) == DragDropKeyStates.ControlKey) { e.Effects = DragDropEffects.Copy; } else { e.Effects = DragDropEffects.Move; } if (e.Effects != currentEffect) { currentEffect = e.Effects; } } else { e.Effects = e.AllowedEffects & ((DragDropEffects.Copy | DragDropEffects.Move) ^ (DragDropEffects.All)); } return(true); }