private static void OnRelativePositionChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { UIElement reference = d as UIElement; if (reference != null) { RelativePositionPanel parent = VisualTreeHelper.GetParent(reference) as RelativePositionPanel; if (parent != null) { parent.InvalidateArrange(); } } }
void TerminalRootSelector_Loaded(object sender, RoutedEventArgs e) { if (this.terminalIndex < 0 || this.associatedRootIndexes == null || this.renderInfo == null) { throw new ArgumentException("Cannot create a root selector using these variables"); } this.mainPanel = this.Template.FindName("mainPanel", this) as RelativePositionPanel; if (this.mainPanel == null) { throw new ArgumentNullException("Cannot find the template item mainPanel"); } Point start = new Point(0.5, 0); double rotation = 0; double rotationStep = 360.0 / this.associatedRootIndexes.Count; foreach (int i in this.associatedRootIndexes) { RotateTransform rotateTransform = new RotateTransform(rotation, 0.5, 0.5); Point rotatedPoint = rotateTransform.Transform(start); SolidColorBrush backgroundBrush = new SolidColorBrush(renderInfo.HighlightedRootColors[i]); if (backgroundBrush.CanFreeze) { backgroundBrush.Freeze(); } TerminalNode tn = new TerminalNode() { Background = backgroundBrush, RootIndex = i, Cursor = Cursors.Hand }; tn.MouseDown += new MouseButtonEventHandler(TerminalNodeMouseDown); RelativePositionPanel.SetRelativePositionX(tn, rotatedPoint.X); RelativePositionPanel.SetRelativePositionY(tn, rotatedPoint.Y); this.mainPanel.Children.Add(tn); rotation += rotationStep; } this.MouseLeftButtonDown += new MouseButtonEventHandler(TerminalRootSelector_MouseLeftButtonDown); this.MouseRightButtonDown += new MouseButtonEventHandler(TerminalRootSelector_MouseRightButtonDown); }