0
我正在创建一个动态的hexgrid,8个10个十六进制的列,椭圆以随机的hexes为中心。Silverlight事件处理程序响应速度非常慢
我原本以为事件处理程序没有加载。现在看来他们正在加载,但反应非常缓慢。当我在一两分钟之后将鼠标放在生成的网格上时,这些格子开始随机填充,并且工具提示开始显示(但直到该十六进制的事件处理程序响应)。实际上最后一个十六进制需要几分钟才能响应mouseover事件。
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;
}
我做错了什么导致这样慢,慢,慢的反应?
作为后续工作,如果我注释掉事件处理程序,无论我等待多久,工具提示都会停止运行。我已经在几个浏览器中测试过了,结果是一样的 – panzerblitzer