将网格转换为网格XAML

将网格转换为网格XAML,xaml,grid,Xaml,Grid,我想在网格中创建一个网格。我尝试了下面的代码,但这不起作用,有人知道为什么吗?你有解决办法吗 <Grid xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" ShowGridLines="true"> <Grid.Background> <LinearGradientBrush> <GradientStop Color="#EEE8AA" /&g

我想在网格中创建一个网格。我尝试了下面的代码,但这不起作用,有人知道为什么吗?你有解决办法吗

<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>

代码是正确的。您将看不到任何内容,因为第二个网格只填充父网格中的特定网格单元,没有内容。尝试添加一些文本框或颜色,您将看到它工作良好

请参见下面的示例。您将在第二个网格中正确显示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
文本框2
文本框3

如果希望在不向网格添加内容的情况下直观地查看网格,请至少尝试将其高度设置为固定值。我将您的代码复制粘贴到
堆栈面板内
将外部
网格
高度
设置为100:

<StackPanel Background="Gray">
    <Grid ShowGridLines="true" Height="100" >
        .......
    </Grid>
</StackPanel>

.......
结果:


代码没有问题,尝试向网格中添加一些内容,例如TextBlock等,或者只是为了确保其工作,使用背景色设置网格的宽度和高度。什么是“不工作”?