2011-10-20 10 views
0

次のシナリオ(Silverlight 4)を想像してみてください。私は2つの長方形を持っています。 1つは黒で、もう1つは白です。どちらも固定サイズ、たとえば50x50です。私も、私はそれらの矩形ではなく、交流の方法を記入する領域(500×500)がある - より良い説明するために、白、黒、白、黒など、怒鳴るのリンクを見てみましょう:動的にm(列)チェス盤でn(行)を生成する

http://screencast.com/t/BwsPSbtg2eaM

http://screencast.com/t/gTuexSSyW

動画(リンク#2)は、私が達成しようとしていることを正確に示しています。

ご協力いただければ幸いです!

ジョーンズ

答えて

1
int totalRectsInaRow = TotalWidth/ WidthOfOneRect; 
    int totalRectsInaColumn = TotalHeight/ HeightOfOneRect; 

    //Create a Grid of Width = TotalWidth and Height = Total Height; 
    //Add columns equal to totalRectsInaColumn and rows equal to totalRectsInaRow in Grid 
    //Set wdith of each column equal to width of one rectangle 
    //set height of each row equal to height of one rectangle 

    bool drawWhite = true; 
    for (int i = 0; i < totalRectsInaColumn; i++) 
    { 
     for (int j = 0; j < totalRectsInaRow; j++) 
     { 
      if (drawWhite) 
      { 
       //draw white rectanlge at i column and j row 
       //basically you create a rectangle and place it in grid on particular location 
       DrawWhileRectangle(i, j); 
       drawWhite = false; 
      } 
      else 
      { 
       //draw black rectanlge at i column and j row 
       //basically you create a rectangle and place it in grid on particular location 
       DrawBlackRectangle(i, j); 
       drawWhite = true; 
      } 
     } 
     drawWhite = !drawWhite; 
    } 
+0

おかげで...私はより多くのXAMLのアプローチを探しています。 –

関連する問題