Silverlight开始

时间:2011-10-17 11:55:21

标签: silverlight graphics draw

我正在尝试使用colums和rows(如国际象棋或其他东西)创建一个字段。 所以,对于这个我使用网格开始和卡住:如果我在单元格中的矩形上按下MouseLeftButton,它什么都没有,但如果我按下微小的行或列,它没关系。

为此我使用矩形,它覆盖在网格上。没关系,如果矩形属性(“填充”)不是空的。但它也是问题:我无法将数据绑定到单元格:\

所以,下一步:我正在尝试绘制矩形并绑定到它们的对象,这些对象必须捕获事件MouseLeftButton。

这样:

public void Rectangle1_MouseLeftButtonDown(sender, e){

        Rectangle r = new Rectangle();
        UIElement s = sender as UIElement;
        r = (Rectangle)(e.OriginalSource);
        int Dx=11;
        int Dy=11;
        Brush pen = new SolidColorBrush(Colors.Orange);
        Thickness thick  = new Thickness();
        thick.Right = 0;
        thick.Bottom = 0;
        Rectangle[,] rex = new Rectangle[(int)Dx,(int)Dy];
        for(int i=0; i<Dx-1; ++i)
            for (int j = 0; j < Dy-1; ++j)
            { 

                int x = i*(int)r.Width/Dx + (int)r.Margin.Left;
                int y = j*(int)r.Height/Dy + (int)r.Margin.Top;
                thick.Left = x; thick.Top = y;
                rex[i,j].Width =(int)r.Width/Dx ;
                rex[i, j].Height = (int)r.Height / Dy;
                rex[i, j].Fill = pen;
                rex[i, j].HorizontalAlignment = HorizontalAlignment.Left;
                rex[i,j].VerticalAlignment = VerticalAlignment.Top;                                 
                rex[i,j].Margin = thick;       
                LayoutRoot.Children.Add(rex[i, j]);
            }
 }

我哪里错了? (大矩形想要分成许多小的也是绑定的对象)

有没有简单的方法来制作这个“国际象棋桌”?

0 个答案:

没有答案