コード ビハインドを使用して 6x7 グリッドに要素を追加するのと同じくらい簡単なことをしようとしています。グリッドは xaml で次のように定義されています。
<Grid x:Name="CalendarGrid" Grid.Row="1" Visibility="Collapsed">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
</Grid>
グリッドにボタンを設定する InitializeCalendar という関数があります。どういうわけか、ボタンを追加する行と列を指定する方法がわかりません。CalendarGrid の行と列を参照するにはどうすればよいですか?
void InitializeCalendar()
{
for (int i = 0; i < 6; i++)
{
for (int j = 0; i < 7; j++)
{
butArray[i + 1, j + 1] = new Button();
//CalendarGrid. I cant find function to specify the row and button
}
}
}
ColumnProperty というプロパティがあることがわかりました。
butArray[i + 1, j + 1].SetValue(Grid.ColumnProperty, 0);
しかし、私のページには非常に多くのグリッドがあります。CalendarGrid を参照するにはどうすればよいですか? 解決策はありますか?
ありがとう、