示例#1
0
        private void ColorCategories_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                canvasDebug.Children.Clear();

                double width  = canvasDebug.ActualWidth;
                double height = canvasDebug.ActualHeight;

                // Reverse so the top priority is drawn first
                foreach (var category in new FlagGenerator.FlagColorCategoriesCache().Categories.Reverse())
                {
                    Rectangle rect = new Rectangle()
                    {
                        Width   = category.Item1.Width / 100 * width,
                        Height  = category.Item1.Height / 100 * height,
                        Fill    = new SolidColorBrush(UtilityWPF.GetRandomColor(0, 255)),
                        ToolTip = category.Item2.ToString(),
                    };

                    rect.MouseDown += new MouseButtonEventHandler((s, b) =>
                    {
                        FlagGenerator.FlagColorCategory cat = UtilityCore.EnumParse <FlagGenerator.FlagColorCategory>(((Rectangle)s).ToolTip.ToString());
                        double?hue = b.LeftButton == MouseButtonState.Pressed ? (double?)null : StaticRandom.NextDouble(360);
                        DrawCategory(cat, hue);
                    });

                    Canvas.SetLeft(rect, category.Item1.X / 100 * width);
                    double top = height - ((category.Item1.Y + category.Item1.Height) / 100 * height);
                    Canvas.SetTop(rect, top);

                    canvasDebug.Children.Add(rect);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), this.Title, MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }