グリッドの削除について質問があります。
グリッドの最後の行またはすべての行を削除しても、グリッドにはまだ何か(実際には最後の行)が表示されています。実際にgrid.rowdefinitions.countが0であることを確認しました。使用したメソッドはremoveAtとremoveRange(0、grid.rowdefinitions.count)です。それのどこが悪いんだい?誰かが理由を言うことができますか?どうもありがとう!
//------------
<Grid DockPanel.Dock="Top" HorizontalAlignment="Left" Name="grid1" ShowGridLines="true" Width="200" Height="200">
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" Grid.Column="0" Text="100" />
<TextBlock Grid.Row="1" Grid.Column="0" Text="200" />
<TextBlock Grid.Row="2" Grid.Column="0" Text="300" />
<TextBlock Grid.Row="3" Grid.Column="0" Text="400" />
<TextBlock Grid.Row="4" Grid.Column="0" Text="500" />
</Grid>
<StackPanel HorizontalAlignment="Left" Orientation="Horizontal" Width="200" DockPanel.Dock="Top">
<Button Width="80" Click="rem5Row">Remove 5 Rows</Button>
</StackPanel>
//--------------
private void rem5Row(object sender, RoutedEventArgs e)
{
if (grid1.RowDefinitions.Count < 5)
{
Console.WriteLine("less than 5!");
}
else
{
grid1.RowDefinitions.RemoveRange(0,grid1.RowDefinitions.Count);
}
}