2013-04-29 90 views
0

enter image description here如何創建網格邊框?

這就是我想要創建的。白色區域爲System.Windows.Shapes.Rectangle,位於Grid。這是我創建網格,列,行和矩形的代碼;

Grid newGrid = new Grid(); 

for(int r=0; r<10; r++) { 
    newGrid.RowDefinitions.Add(
     new RowDefinition { Height = new GridLength(30) }); 
    for(int c=0; c<10; c++) { 
     newGrid.ColumnDefinitions.Add(
      new ColumnDefinition { Width = new GridLength(30) }); 
     Rectangle rec = new Rectangle{ 
      Fill = new SolidColorBrush(Colors.White) 
     }; 
     Grid.SetColumn(rec, c); 
     Grid.SetRow(rec, r); 
     newGrid.Children.Add(rec); 
    } 
} 

LayoutRoot.Children.Add(newGrid); 

但我還沒有任何想法如何可以添加邊框,因爲我們可以在圖片中看到。感謝您的建議。

+0

你可以考慮使用的TileBrush(http://msdn.microsoft.com/en-us/library/system.windows.media.tilebrush.aspx) – sircodesalot 2013-04-29 14:01:12

+0

@miqbal發生了什麼事你的代碼?它不工作還是什麼? – Mani 2013-04-29 15:27:08

回答

0

嘗試

SolidColorBrush blackBrush = new SolidColorBrush(); 
    blackBrush.Color = Colors.Black; 

rec.Stroke = blackBrush; 
+0

但是在這種情況下,就好像網格邊框的厚度小於單元格邊框。 – miqbal 2013-04-29 14:25:21