private static void OnBusyStateChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { var element = d as FrameworkElement; if (element != null) { var isBusy = (bool)e.NewValue; if (isBusy) { var busyCtrl = new BusyControl(); Adorner adorner = new ControlAdorner(element, busyCtrl); AdornerLayer.GetAdornerLayer(element).Add(adorner); element.SetValue(AdornerProperty, adorner); } else { var adorner = element.GetValue(AdornerProperty) as Adorner; if (adorner != null) { AdornerLayer.GetAdornerLayer(element).Remove(adorner); element.SetValue(AdornerProperty, null); } } } }
protected override void Activate(ModelItem item) { designObject = item.GetCurrentValue() as LinkableControl;//获得被点击的控件对象 if (designObject != null) { designCanvas = designObject.Parent as Panel; DesignerView v = DesignerView.FromContext(Context); adorner = new ControlAdorner(designObject); adorner.RenderTransform = new ScaleTransform(v.ZoomLevel, v.ZoomLevel); foreach (var pin in adorner.Children) { pin.MouseLeftButtonDown += new MouseButtonEventHandler(Pin_MouseLeftButtonDown); //按下左键选中hitPin,开始拖动 pin.MouseMove += new MouseEventHandler(Pin_MouseMove); //移动鼠标,开始找寻目标连接节点 } AdornerPanel.SetAdornerHorizontalAlignment(adorner, AdornerHorizontalAlignment.Stretch); AdornerPanel.SetAdornerVerticalAlignment(adorner, AdornerVerticalAlignment.Stretch); _panel.Children.Add(adorner); Adorners.Add(_panel); v.ZoomLevelChanged += (s, e) => { adorner.RenderTransform = new ScaleTransform(v.ZoomLevel, v.ZoomLevel); }; } base.Activate(item); }
private void Pin_MouseEnter(object sender, MouseEventArgs e) { _adornerLayer = AdornerLayer.GetAdornerLayer(this); FrameworkElement element = DescriptionItemTemplate.LoadContent() as FrameworkElement; if (element == null) { return; } element.DataContext = this.DataContext; _adorner = new ControlAdorner(this, element); _adornerLayer.Add(_adorner); }
private void OnLoaded(object sender, RoutedEventArgs e) { _adorner = new ControlAdorner(AssociatedObject, AdornerTemplate.LoadContent() as FrameworkElement, AssociatedObject?.DataContext, AdornerProperties.GetAdornerContext(this)); _adorner.Margin = new Thickness(-6, 0, -6, 0); HideAdorner(); Application.Current.MainWindow.PreviewMouseLeftButtonDown += OnPreviewMouseDown; Application.Current.MainWindow.PreviewMouseLeftButtonUp += OnPreviewMouseUp; Application.Current.MainWindow.PreviewMouseMove += OnPreviewMouseMove; if (MouseEvent == OverlookMouseBehavior.OnMouseOverAndCtrl) { Application.Current.MainWindow.PreviewKeyDown += OnPreviewKeyDown; } }
private void Hide() { System.Diagnostics.Debug.WriteLine("Hide()"); RemoveMouseCapture(content); RemoveMouseCapture(_keeper); if (_adorner != null) { //System.Diagnostics.Debug.WriteLine("Hide() exists _adorner"); AdornerLayer.GetAdornerLayer(this).Remove(_adorner); _adorner.Child = null; _adorner = null; content.Visibility = System.Windows.Visibility.Collapsed; this.Content = content; } }
private void Show() { var holder = GetAdornerLayerHolderElement(); if (_adorner == null) { RemoveVisualChild(VisualTreeHelper.GetChild(this, 0) as FrameworkElement); var content = FormElement; if (double.IsNaN(content.Width)) { //var wBinding = new Binding("ActualWidth"); //wBinding.Source = holder; //BindingOperations.SetBinding(content, FrameworkElement.WidthProperty, wBinding); //content.Width = holder.ActualWidth; } if (double.IsNaN(content.Height)) { //var hBinding = new Binding("ActualHeight"); //hBinding.Source = holder; //BindingOperations.SetBinding(content, FrameworkElement.HeightProperty, hBinding); //content.Width = holder.ActualHeight; } try { _adorner = new ControlAdorner(this /*, holder*/) { Child = VisualTreeHelper.GetParent(content) as FrameworkElement }; } catch (Exception ex) { throw ex; } } var adrLayer = AdornerLayer.GetAdornerLayer(this); //LogicalTreeHelper adrLayer.Remove(_adorner); adrLayer.Add(_adorner); }
/// <summary> /// The remove adorner. /// </summary> private void RemoveAdorner() { if (this.adorner == null || this.adornerLayer == null) { return; } if (this.adornerDragDrop != null) { ControlAdornerDragDrop.Detach(this.adornerDragDrop); this.adornerDragDrop = null; } this.adornerLayer.Remove(this.adorner); this.adorner.Child = null; this.adorner = null; this.adornerLayer = null; this.RegisterBeingMovedOut(); }
/// <summary> /// The create adorner. /// </summary> private void CreateAdorner() { if (this.adorner != null || (Application.Current.MainWindow == null && this.userDefinedAdorner == null)) { return; } var adornedElement = this.GetAdornerElement(); if (adornedElement == null) { return; } AdornerLayer layer = AdornerLayer.GetAdornerLayer(adornedElement); if (layer == null) { return; } this.isPositionCalculated = false; var ad = new ControlAdorner(adornedElement) { Child = this, Focusable = false }; KeyboardNavigation.SetTabNavigation(ad, KeyboardNavigationMode.None); layer.Add(ad); this.adorner = ad; this.adornerLayer = layer; if (this.IsPinned && this.adornerDragDrop == null) { this.adornerDragDrop = ControlAdornerDragDrop.Attach(this.adorner); } this.RegisterBeingInFront(); }
private void Show() { if (_adorner == null) { try { _adorner = new ControlAdorner(this) { Child = content }; } catch (Exception ex) { throw ex; } //System.Diagnostics.Debug.WriteLine("Show() new _adorner"); } AdornerLayer.GetAdornerLayer(this).Remove(_adorner); AdornerLayer.GetAdornerLayer(this).Add(_adorner); GetMouseCapture(content); }
private void Pin_MouseLeave(object sender, MouseEventArgs e) { _adornerLayer.Remove(_adorner); _adorner = null; }
private static void OnOffsetYChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { ControlAdorner instance = (ControlAdorner)d; instance.OnOffsetYChanged(e); }