我想在网格中创建一个网格。我尝试了以下一段代码,但这不起作用,有谁知道为什么?你有解决方案吗?
<Grid xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" ShowGridLines="true">
<Grid.Background>
<LinearGradientBrush>
<GradientStop Color="#EEE8AA" />
<GradientStop Color="#2F4F4F" Offset="1" />
</LinearGradientBrush>
</Grid.Background>
<Grid.RowDefinitions>
<RowDefinition Height="10*" />
<RowDefinition Height="90*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="10*" />
<ColumnDefinition Width="80*" />
<ColumnDefinition Width="10*" />
</Grid.ColumnDefinitions>
<Grid Grid.Row="0" Grid.Column="1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="100*" />
</Grid.RowDefinitions>
</Grid>
</Grid>
答案 0 :(得分:0)
代码是正确的。你不会看到任何东西,因为第二个网格只填充父网格中的特定网格单元并且没有内容。尝试添加一些文本框或颜色,你会发现它工作正常。
请参阅下面的示例。您将在第二个网格中正确显示3个文本框。
<Grid xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" ShowGridLines="true">
<Grid.Background>
<LinearGradientBrush>
<GradientStop Color="#EEE8AA" />
<GradientStop Color="#2F4F4F" Offset="1" />
</LinearGradientBrush>
</Grid.Background>
<Grid.RowDefinitions>
<RowDefinition Height="10*" />
<RowDefinition Height="90*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="10*" />
<ColumnDefinition Width="80*" />
<ColumnDefinition Width="10*" />
</Grid.ColumnDefinitions>
<Grid Grid.Row="0" Grid.Column="1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="100*" />
</Grid.RowDefinitions>
<TextBlock Grid.Column="0" Grid.Row="0">TextBox1</TextBlock>
<TextBlock Grid.Column="1" Grid.Row="0">TextBox2</TextBlock>
<TextBlock Grid.Column="2" Grid.Row="0">TextBox3</TextBlock>
</Grid>
</Grid>
答案 1 :(得分:0)
如果您希望直观地看到网格而不向其添加内容,请至少尝试将其Height
/ Width
设置为固定值。我将您的代码复制粘贴在StackPanel
内,将外部Grid
的{{1}}设置为100:
Height
结果: