キャンバスにグリッドを追加し、四角形の中に入れたいと思います。ここでキャンバスにControls.Gridを追加する方法
私のコード
Grid gridForModules = new Grid();
Canvas.SetLeft(gridForModules, 600);
Canvas.SetTop(gridForModules, 80);
AddRowsOfGrid(gridForModules, 5);
AddColumnsOfGrid(gridForModules, 8);
gridForModules.ShowGridLines = true;
m_grid.RegisterName("ModulesGRID", gridForModules);
m_canvas.Children.Add(gridForModules);
Rectangle rect = new Rectangle();
Grid.SetColumn(rect, 2);
Grid.SetRow(rect, 2);
Grid.SetRowSpan(rect, 2);
Grid.SetColumnSpan(rect, 2);
rect.Fill = new SolidColorBrush(Colors.Coral);
rect.Name = "ModuloEsempio";
gridForModules.Children.Add(rect);
m_grid.RegisterName(rect.Name, rect);
おかげ
コードを使用すると、正確には期待どおりに機能しません。 – haindl
グリッドの線が表示されず、矩形が表示されません。 – fede186
あなたのコードは私のテストでうまくいくようです。 'AddRowsOfGrid'にRowDefinitionsの' Height'を、 'AddColumnsOfGrid'にColumnDefinitionsの' Width'を設定しましたか?はいの場合、そのメソッドのコードを投稿できますか? (グリッドは 'SetLeft'が' 600'のため、少し右にあることに注意してください) – haindl