2012-12-02 66 views
1

我有一個GridView:的Windows 8 - 將GridView控件的頭在C#

<GridView HorizontalAlignment="Left" Width="400" Height="400" Header="AAAAAA"> 
      <GridViewItem Content="GridViewItem" Margin="0"/> 
      <GridViewItem Content="GridViewItem" Margin="0"/> 
      <GridViewItem Content="GridViewItem" Margin="0"/> 
      <GridViewItem Content="GridViewItem" Margin="0"/> 
      <GridViewItem Content="GridViewItem" Margin="0"/> 
      <GridViewItem Content="GridViewItem" Margin="0"/> 
      <GridViewItem Content="GridViewItem" Margin="0"/> 
      <GridViewItem Content="GridViewItem" Margin="0"/> 
      <GridViewItem Content="GridViewItem" Margin="0"/> 
      <GridViewItem Content="GridViewItem" Margin="0"/> 
      <GridViewItem Content="GridViewItem" Margin="0"/> 
      <GridViewItem Content="GridViewItem" Margin="0"/> 
      <GridViewItem Content="GridViewItem" Margin="0"/> 
      <GridViewItem Content="GridViewItem" Margin="0"/> 
      <GridViewItem Content="GridViewItem" Margin="0"/> 
      <GridViewItem Content="GridViewItem" Margin="0"/> 
      <GridViewItem Content="GridViewItem" Margin="0"/> 
      <GridViewItem Content="GridViewItem" Margin="0"/> 
      <GridViewItem Content="GridViewItem" Margin="0"/> 
      <GridViewItem Content="GridViewItem" Margin="0"/> 
     </GridView> 

enter image description here

我只想說AAAAA上GridView的上側,而左側的地方介入位置我的GridViewItem。您知道,就像在Windows 8上的音樂應用程序一樣,標題「正在播放」或「最流行」被放置在GridView的上方。怎麼做?

回答

1

試試這個:

<GridView HorizontalAlignment="Left" Width="400" Height="400" Header="AAAAA"> 
     <GridView.ItemsPanel> 
      <ItemsPanelTemplate> 
       <VariableSizedWrapGrid Orientation="Horizontal" Width="400" /> 
      </ItemsPanelTemplate> 
     </GridView.ItemsPanel> 
     <GridViewItem Content="GridViewItem" Margin="0"/> 
     <GridViewItem Content="GridViewItem" Margin="0"/> 
     <GridViewItem Content="GridViewItem" Margin="0"/> 
     <GridViewItem Content="GridViewItem" Margin="0"/> 
     <GridViewItem Content="GridViewItem" Margin="0"/> 
     <GridViewItem Content="GridViewItem" Margin="0"/> 
    </GridView> 

或者,而不是使用GridView的頭,你可以做這樣的事情:

<Grid Width="400" Height="300"> 
     <Grid.RowDefinitions> 
      <RowDefinition Height="Auto" /> 
      <RowDefinition Height="*" /> 
     </Grid.RowDefinitions> 
     <TextBlock Style="{StaticResource SubheaderTextStyle}" Text="My Header" Margin="0 20" /> 
     <GridView Grid.Row="1"> 
      <GridViewItem Content="GridViewItem" Margin="0"/> 
      <GridViewItem Content="GridViewItem" Margin="0"/> 
      <GridViewItem Content="GridViewItem" Margin="0"/> 
     </GridView> 
    </Grid> 
+0

你的選擇是天才!它留下了我的上下文有一個標題,但創建一個TextBlock重複,做我想要的確切的東西。謝啦 –

0

試試這個:

<GridView HorizontalAlignment="Left" Width="400" Height="400"> 
     <GridView.Header> <TextBlock Text="AAAAA" Margin="240,0,0,0"/> 
     </GridView.Header> 
     <GridViewItem Content="GridViewItem" Margin="0"/> 
     <GridViewItem Content="GridViewItem" Margin="0"/> 
     <GridViewItem Content="GridViewItem" Margin="0"/> 
     <GridViewItem Content="GridViewItem" Margin="0"/> 
     <GridViewItem Content="GridViewItem" Margin="0"/> 
     <GridViewItem Content="GridViewItem" Margin="0"/> 
     <GridViewItem Content="GridViewItem" Margin="0"/> 
     <GridViewItem Content="GridViewItem" Margin="0"/> 
     <GridViewItem Content="GridViewItem" Margin="0"/> 
     <GridViewItem Content="GridViewItem" Margin="0"/> 
     <GridViewItem Content="GridViewItem" Margin="0"/> 
     <GridViewItem Content="GridViewItem" Margin="0"/> 
     <GridViewItem Content="GridViewItem" Margin="0"/> 
     <GridViewItem Content="GridViewItem" Margin="0"/> 
     <GridViewItem Content="GridViewItem" Margin="0"/> 
     <GridViewItem Content="GridViewItem" Margin="0"/> 
     <GridViewItem Content="GridViewItem" Margin="0"/> 
     <GridViewItem Content="GridViewItem" Margin="0"/> 
     <GridViewItem Content="GridViewItem" Margin="0"/> 
     <GridViewItem Content="GridViewItem" Margin="0"/> 
    </GridView> 

您可以設置任何你想要的屬性TextBlock的

+0

仍然出現在GridView控件的左側,而不是工作 –

0
<GridView HorizontalAlignment="Left" Width="400" Height="400" Header="AAAAA"> 
     <GridView.ItemsPanel> 
      <ItemsPanelTemplate> 
       <VariableSizedWrapGrid Orientation="Horizontal" Margin="-80,20,0,0" Width="400" /> 
      </ItemsPanelTemplate> 
     </GridView.ItemsPanel> 
     <GridViewItem Content="GridViewItem" Margin="0"/> 
     <GridViewItem Content="GridViewItem" Margin="0"/> 
     <GridViewItem Content="GridViewItem" Margin="0"/> 
     <GridViewItem Content="GridViewItem" Margin="0"/> 
     <GridViewItem Content="GridViewItem" Margin="0"/> 
     <GridViewItem Content="GridViewItem" Margin="0"/> 
    </GridView> 

Or you can adjust the margin of the variableSizedWrapGrid, so that the alignment of the header and Items should appear in same line 
0

< --Try本 - >

<GridView HorizontalAlignment="Left" Width="400" Grid.Row="1" Height="400"> 
<GridView.Header> 
<TextBlock Text="AAAAA" /> 
</GridView.Header> 
<GridView.ItemsPanel> 
<ItemsPanelTemplate> 
<VariableSizedWrapGrid Margin="-35,20,0,0"/> 
</ItemsPanelTemplate> 
</GridView.ItemsPanel> 
<GridViewItem Content="GridViewItem" Margin="0"/> 
<GridViewItem Content="GridViewItem" Margin="0"/> 
<GridViewItem Content="GridViewItem" Margin="0"/> 
<GridViewItem Content="GridViewItem" Margin="0"/> 
<GridViewItem Content="GridViewItem" Margin="0"/> 
<GridViewItem Content="GridViewItem" Margin="0"/> 
<GridViewItem Content="GridViewItem" Margin="0"/> 
<GridViewItem Content="GridViewItem" Margin="0"/> 
<GridViewItem Content="GridViewItem" Margin="0"/> 
<GridViewItem Content="GridViewItem" Margin="0"/> 
<GridViewItem Content="GridViewItem" Margin="0"/> 
<GridViewItem Content="GridViewItem" Margin="0"/> 
<GridViewItem Content="GridViewItem" Margin="0"/> 
<GridViewItem Content="GridViewItem" Margin="0"/> 
<GridViewItem Content="GridViewItem" Margin="0"/> 
<GridViewItem Content="GridViewItem" Margin="0"/> 
<GridViewItem Content="GridViewItem" Margin="0"/> 
<GridViewItem Content="GridViewItem" Margin="0"/> 
<GridViewItem Content="GridViewItem" Margin="0"/> 
<GridViewItem Content="GridViewItem" Margin="0"/> 
</GridView>