void d_Click(object sender, RoutedEventArgs e) { SupressConnectorNodes = AdornerToggleButtons.Any(t => t.IsChecked == true); }
private void InsertAdorners() { if (VisualTreeHelper.GetChildrenCount(AssociatedObject) == 0) { return; } AssociatedObject.LayoutUpdated -= AssociatedObjectLayoutUpdated; _beginInt = AssociatedObject.IsInitialized; if (!_beginInt) { AssociatedObject.BeginInit(); } // // Create visual for adorners // FrameworkElement topVisuals = TopTemplate.LoadContent() as FrameworkElement; if (topVisuals != null) { var topBorder = topVisuals.FindName("AdornerBorder") as FrameworkElement; if (topBorder != null) { var behaviors = Interaction.GetBehaviors(AssociatedObject); var actualSizeBehavior = behaviors.FirstOrDefault(b => b.GetType() == typeof(ActualSizeBindingBehavior)) as ActualSizeBindingBehavior; if (actualSizeBehavior != null) { var widthBinding = new Binding { Source = actualSizeBehavior, Path = new PropertyPath("ActualWidth"), Converter = new DoubleToMarginLeftConverter() }; topBorder.SetBinding(FrameworkElement.MarginProperty, widthBinding); } } } if (topVisuals != null && DataContext != null) { topVisuals.DataContext = DataContext; } // // Setup intercept for supressing the connector nodes // _rootAdornerLayer = AdornerLayer.GetAdornerLayer(AssociatedObject); if (_rootAdornerLayer != null) { _rootAdornerLayer.LayoutUpdated += AdornerLayerOnMouseLeave; } // // Get controls from visual tree // Border childBorder = VisualTreeHelper.GetChild(AssociatedObject, 0) as Border; if (childBorder == null) { return; } Grid hostGrid = childBorder.Child as Grid; if (hostGrid == null) { return; } Border titleBarBorder = GetColoursBorder(hostGrid); if (titleBarBorder == null) { return; } // // Set colour attached properties // Binding backgroundBinding = new Binding("Background"); backgroundBinding.Source = titleBarBorder; Binding borderBrushBinding = new Binding("BorderBrush"); borderBrushBinding.Source = titleBarBorder; if (topVisuals != null) { topVisuals.BeginInit(); topVisuals.SetBinding(TitleBarBackgroundProperty, backgroundBinding); topVisuals.SetBinding(TitleBarBorderBrushProperty, borderBrushBinding); topVisuals.EndInit(); } // // Insert adorners // AdornerDecorator decorator = new AdornerDecorator(); childBorder.Child = null; decorator.Child = hostGrid; childBorder.Child = decorator; AdornerLayer adornerLayer = AdornerLayer.GetAdornerLayer(hostGrid); if (!_beginInt) { AssociatedObject.BeginInit(); } TopVisualsAdornerWrapper topVisualsAdornerWrapper = new TopVisualsAdornerWrapper(hostGrid, topVisuals, AssociatedObject); adornerLayer.Add(topVisualsAdornerWrapper); if (!_beginInt) { adornerLayer.EndInit(); AssociatedObject.EndInit(); } AdornerToggleButtons.Clear(); topVisualsAdornerWrapper.Descendents().OfType <AdornerToggleButton>().ToList() .ForEach(d => { AdornerToggleButtons.Add(d); d.Click += d_Click; }); }