0

我正在创建一个动态六角网格,8 列 10 个六角形,一个椭圆以随机六角形为中心。

我原本以为事件处理程序没有加载。现在看起来他们正在加载,但反应非常缓慢。当我在一两分钟后将鼠标悬停在生成的网格上时,十六进制开始随机填充并且工具提示开始显示(但直到该十六进制的事件处理程序响应)。最后一个十六进制响应鼠标悬停事件实际上需要几分钟时间。

     private void CreateHexGrid(int columns, int rows, double length)
    {
       //I create a jagged array of points, 
       //hexpoint[# of columns, # of rows, 6 points]
       //the base (0,0) hex is generated point by point 
       //mathematically based on the length of one side 
       //then each subsequent hex is mathematically
       //created based on the points of the previous hex.
       //Finally, I instantiate each Polygon hex and fill 
       //its points collection using the array.
              PointCollection points = new PointCollection();
              SolidColorBrush blackBrush = new SolidColorBrush(Colors.Black);
              SolidColorBrush clearBrush = new SolidColorBrush(Colors.Transparent);
              Polygon hex = new Polygon();
              hex.Stroke = blackBrush;
              hex.StrokeThickness = 1;
              hex.Name = "Hex" + column.ToString() + row.ToString();

              for (int point = 0; point < 6; point++)
               {
                  points.Add(HexPoint[column, row, point]);
               }

              hex.Points = points;
              ToolTipService.SetToolTip(hex, hex.Name);
              hex.MouseEnter += new MouseEventHandler(hex_MouseEnter);
              cnvsHexGrid.Children.Add(hex);
       //....
     }

目前我有处理程序只是试图改变多边形/椭圆的填充颜色来测试。如果单击十六进制,我最终想生成一个交互式弹出窗口。

    void hex_MouseEnter(object sender, MouseEventArgs e)
    {
        var hex = sender as Polygon;
        SolidColorBrush blueFill = new SolidColorBrush(Colors.Blue);
        hex.Fill = blueFill;
    }

我做错了什么导致如此缓慢,缓慢,缓慢的反应?

4

1 回答 1

0

在 Load_Main 中添加一个处理程序似乎有助于解决这个问题。

于 2013-01-09T06:34:30.843 回答