0

10 個の hex の 8 列からなる動的 hexgrid を作成しています。楕円はランダムな hex の中心にあります。

私は当初、イベント ハンドラーが読み込まれていないと考えていました。ロードしているように見えますが、反応が非常に遅いです。1、2 分後に生成されたグリッドにマウスを合わせると、ヘックスがランダムに塗りつぶされ始め、ツールチップが表示され始めます (ただし、そのヘックスのイベント ハンドラーが応答するまでは表示されません)。最後のヘックスがマウスオーバー イベントに応答するまで、実際には数分かかります。

     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 に答える