2014-03-04 83 views
0

我想創建網格到網格中。我嘗試了下面這段代碼,但這不起作用,有人知道爲什麼嗎?你有解決方案嗎?將網格劃分爲網格XAML

<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

沒有錯代碼,嘗試加入一些內容到網格例如TextBlock等或只是爲了確保其工作,設置具有背景顏色的網格的寬度和高度。 – Zeshan

+0

你是什麼意思「不起作用」? – har07

回答

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

如果你想看到網格在視覺上沒有將內容添加到它,至少嘗試設置它Height/Width爲固定值。我複製粘貼你的代碼中StackPanel設置外GridHeight 100:

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

結果:

enter image description here