private void AddIndex(Point posP, int index) { System.Windows.Controls.TextBlock textBlock = new System.Windows.Controls.TextBlock(); textBlock.Text = index.ToString(); textBlock.Foreground = Brushes.DarkGreen; textBlock.FontSize = indexFontSize; textBlock.SetValue(System.Windows.Controls.Canvas.LeftProperty, posP.X); textBlock.SetValue(System.Windows.Controls.Canvas.TopProperty, posP.Y); canvas.Children.Add(textBlock); }
private System.Windows.Controls.Grid CreateVerticalGrid( System.Windows.Controls.Grid parentGrid, double currentLeftMargin, double currentTopMargin, MenuItem parentMenuItem, System.Windows.Controls.TextBlock txt, System.Windows.Controls.Grid grdVertical) { var verticalGrid = new System.Windows.Controls.Grid() { Width = verticalMenuWidth, HorizontalAlignment = HorizontalAlignment.Left, VerticalAlignment = VerticalAlignment.Top }; grdVertical = new System.Windows.Controls.Grid() { Margin = new Thickness(currentLeftMargin, currentTopMargin, 0, 0), HorizontalAlignment = HorizontalAlignment.Left, VerticalAlignment = VerticalAlignment.Top }; grdVertical.RowDefinitions.Add(new System.Windows.Controls.RowDefinition() { Height = new GridLength(35) }); // largeur menuitem grdVertical.RowDefinitions.Add(new System.Windows.Controls.RowDefinition() { Height = new GridLength(35) }); parentGrid.Children.Add(grdVertical); parentMenuItem.MenuGrid = grdVertical; var brdAroundVerticalParent = new System.Windows.Controls.Border() { Margin = new Thickness(1, 1, 1, 1), CornerRadius = new CornerRadius(0), BorderBrush = borderBrush, BorderThickness = new Thickness(1), Background = background, Height = 35, HorizontalAlignment = HorizontalAlignment.Left, VerticalAlignment = VerticalAlignment.Top }; brdAroundVerticalParent.RenderTransform = new TranslateTransform() { Y = 0 }; brdAroundVerticalParent.SetValue(System.Windows.Controls.Grid.RowProperty, 0); brdAroundVerticalParent.SetValue(System.Windows.Controls.Canvas.ZIndexProperty, parentMenuItem.Level * 100); if (parentMenuItem.Level == 1) { brdAroundVerticalParent.Child = txt; } if (parentMenuItem.Level > 1) { brdAroundVerticalParent.Visibility = Visibility.Collapsed; } brdAroundVerticalParent.MouseLeftButtonUp += new MouseButtonEventHandler(brdAroundVerticalParent_MouseLeftButtonUp); grdVertical.Children.Add(brdAroundVerticalParent); var brdAroundVerticalChildren = new System.Windows.Controls.Border() { CornerRadius = new CornerRadius(2), BorderBrush = borderBrush, BorderThickness = new Thickness(1), HorizontalAlignment = HorizontalAlignment.Left, VerticalAlignment = VerticalAlignment.Top }; brdAroundVerticalChildren.Child = verticalGrid; brdAroundVerticalChildren.RenderTransform = new TranslateTransform() { Y = 0 }; brdAroundVerticalChildren.SetValue(System.Windows.Controls.Grid.RowProperty, 1); grdVertical.Children.Add(brdAroundVerticalChildren); Rectangle rectHideLine = new Rectangle() { Margin = new Thickness(0, 0, 0, 0), HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch, Stroke = background, VerticalAlignment = System.Windows.VerticalAlignment.Top, Height = 1 }; rectHideLine.SetValue(System.Windows.Controls.Grid.RowProperty, 1); Rectangle rectLineLeft = new Rectangle() { Margin = new Thickness(0, 0, 0, 0), Fill = borderBrush, VerticalAlignment = System.Windows.VerticalAlignment.Top, HorizontalAlignment = System.Windows.HorizontalAlignment.Left, Width = 1, Height = 35 }; rectLineLeft.SetValue(System.Windows.Controls.Grid.RowProperty, 0); rectLineLeft.SetValue(System.Windows.Controls.Grid.RowSpanProperty, 2); if (parentMenuItem.Level < 2) { grdVertical.Children.Add(rectHideLine); grdVertical.Children.Add(rectLineLeft); } int gridRow = 0; foreach (var mi3 in parentMenuItem.MenuItems) { mi3.ParentName = parentMenuItem.Name; mi3.Level = parentMenuItem.Level + 1; var focusRectangle3 = new Rectangle() { Fill = focusBrush, HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch, VerticalAlignment = System.Windows.VerticalAlignment.Stretch, Visibility = Visibility.Collapsed, Margin = new Thickness(1, 0, 10, 0), RadiusX = 2, RadiusY = 2 }; var focusRectangle4 = new Rectangle() { Stroke = focusBorderBrush, HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch, VerticalAlignment = System.Windows.VerticalAlignment.Stretch, Visibility = Visibility.Collapsed, Margin = new Thickness(1, 0, 10, 0), RadiusX = 2, RadiusY = 2 }; var separatorRectangle = new Rectangle() { Height = 1, Fill = new SolidColorBrush(Colors.Black), //Fill = new SolidColorBrush(Color.FromArgb(0xFF, 0xA0, 0xA0, 0xA0)), HorizontalAlignment = HorizontalAlignment.Stretch, VerticalAlignment = VerticalAlignment.Center, Margin = new Thickness(2, 0, 2, 0) }; separatorRectangle.SetValue(System.Windows.Controls.Grid.ColumnProperty, 1); separatorRectangle.SetValue(System.Windows.Controls.Grid.ColumnSpanProperty, 2); System.Windows.Controls.Border brdImage = new System.Windows.Controls.Border() { Width = 24, Height = 35, HorizontalAlignment = HorizontalAlignment.Left, Background = new SolidColorBrush(Colors.DarkGray)//imageBackgroundBrush }; System.Windows.Controls.Image imgLevel2 = new System.Windows.Controls.Image() { Width = 16, Height = 16, HorizontalAlignment = HorizontalAlignment.Left, Margin = new Thickness(4, 0, 0, 0), Opacity = mi3.IsEnabled ? 1.0 : 0.5 }; imgLevel2.SetValue(System.Windows.Controls.Grid.ColumnProperty, 0); System.Windows.Controls.Image imgArrow = new System.Windows.Controls.Image() { Width = 16, Height = 16, HorizontalAlignment = HorizontalAlignment.Left, Margin = new Thickness(0, 0, 0, 0), Opacity = mi3.IsEnabled ? 1.0 : 0.5 }; imgArrow.SetValue(System.Windows.Controls.Grid.ColumnProperty, 2); imgArrow.Source = new BitmapImage(new Uri(string.Format(@"{0}Arrow.png", imagesPath), UriKind.Relative)); imgArrow.Visibility = mi3.MenuItems.Count > 0 ? Visibility.Visible : Visibility.Collapsed; if (mi3.IsCheckable) { if (mi3.IsChecked) { mi3.ImagePath = string.Format("{0}Checked.png", imagesPath); } else { mi3.ImagePath = null; } } else { if (mi3.ImagePath == null) { mi3.ImagePath = string.Format("{0}{1}.png", imagesPath, mi3.Name); } } if (mi3.ImagePath != null) { imgLevel2.Source = new BitmapImage(new Uri(mi3.ImagePath, UriKind.Relative)); } var textBlockLevel2 = new System.Windows.Controls.TextBlock() { Text = mi3.Text, Margin = new Thickness(8, 4, 8, 4), VerticalAlignment = VerticalAlignment.Center, // Foreground = new SolidColorBrush(Colors.Purple),//foreground, Opacity = mi3.IsEnabled ? 1.0 : 0.5 }; var gridLevel2 = new System.Windows.Controls.Grid() { Background = background }; gridLevel2.ColumnDefinitions.Add(new System.Windows.Controls.ColumnDefinition() { Width = new GridLength(24) }); gridLevel2.ColumnDefinitions.Add(new System.Windows.Controls.ColumnDefinition() { Width = new GridLength(verticalMenuWidth - 40) }); gridLevel2.ColumnDefinitions.Add(new System.Windows.Controls.ColumnDefinition() { Width = new GridLength(24), MinWidth = 24 }); focusRectangle3.SetValue(System.Windows.Controls.Grid.ColumnProperty, 0); focusRectangle3.SetValue(System.Windows.Controls.Grid.ColumnSpanProperty, 3); textBlockLevel2.SetValue(System.Windows.Controls.Grid.ColumnProperty, 1); focusRectangle4.SetValue(System.Windows.Controls.Grid.ColumnProperty, 0); focusRectangle4.SetValue(System.Windows.Controls.Grid.ColumnSpanProperty, 3); verticalGrid.RowDefinitions.Add(new System.Windows.Controls.RowDefinition() { Height = new GridLength(22) }); if (mi3.Text.Equals("-")) { gridLevel2.Children.Add(brdImage); gridLevel2.Children.Add(separatorRectangle); verticalGrid.RowDefinitions[verticalGrid.RowDefinitions.Count - 1].Height = new GridLength(2); separatorRectangle.SetValue(System.Windows.Controls.Grid.ColumnProperty, 1); separatorRectangle.SetValue(System.Windows.Controls.Grid.ColumnSpanProperty, 2); } else { gridLevel2.Children.Add(brdImage); gridLevel2.Children.Add(focusRectangle3); gridLevel2.Children.Add(imgLevel2); gridLevel2.Children.Add(textBlockLevel2); gridLevel2.Children.Add(imgArrow); gridLevel2.Children.Add(focusRectangle4); gridLevel2.MouseEnter += new MouseEventHandler(gridLevel2_MouseEnter); gridLevel2.MouseLeave += new MouseEventHandler(gridLevel2_MouseLeave); gridLevel2.MouseLeftButtonUp += new MouseButtonEventHandler(gridLevel2_MouseLeftButtonUp); } gridLevel2.Tag = mi3; gridLevel2.SetValue(System.Windows.Controls.Grid.RowProperty, gridRow); verticalGrid.Children.Add(gridLevel2); grdVertical.RowDefinitions[1].Height = new GridLength(grdVertical.RowDefinitions[1].Height.Value + 22); gridRow++; if (mi3.MenuItems.Count > 0) { CreateVerticalGrid(parentGrid, currentLeftMargin + verticalMenuWidth, currentTopMargin, mi3, txt, grdVertical); } if (mi3.Text.Equals("-")) { currentTopMargin += 2; } else { currentTopMargin += 22; } if (!menuDictionary.ContainsKey(mi3.Name)) { menuDictionary.Add(mi3.Name, mi3); } } grdVertical.Visibility = Visibility.Collapsed; grdVertical.MouseLeave += new MouseEventHandler(grdVertical_MouseLeave); // modificatioN le 03/10/2012 GBOGUE // if (!menuDictionary.ContainsKey(parentMenuItem.Name)) menuDictionary.Add(parentMenuItem.Name, parentMenuItem); grdVertical.SetValue(System.Windows.Controls.Canvas.ZIndexProperty, parentMenuItem.Level * 100); return(grdVertical); }