2012-05-07 8 views
1

誰かがGridViewItemからすべてのパディングを削除する方法を知っていますか?私は非常に小さい項目を使用しています(小さすぎるものではありませんが、下の図では誇張しています)。項目を選択するといくつかのパディングがあり、本当に悪くなります。これは私が何を意味するかです:GridViewItemからパディングを削除する

enter image description here

画像のコードはこれです:事前に

<GridView Margin="120,80,0,0" 
        SelectionMode="Multiple"> 
      <GridView.ItemsPanel> 
       <ItemsPanelTemplate> 
        <VirtualizingStackPanel 
         Orientation="Horizontal" /> 
       </ItemsPanelTemplate> 
      </GridView.ItemsPanel> 
      <GridView.ItemContainerStyle> 
       <Style TargetType="GridViewItem"> 
        <Setter Property="HorizontalAlignment" Value="Center" /> 
        <Setter Property="VerticalAlignment" Value="Center" /> 
       </Style> 
      </GridView.ItemContainerStyle> 
      <Rectangle Height="10" Width="10" Fill="Red" /> 
      <Rectangle Height="10" Width="10" Fill="Orange" /> 
      <Rectangle Height="10" Width="10" Fill="Blue" /> 
      <Rectangle Height="10" Width="10" Fill="Green" /> 
      <Rectangle Height="10" Width="10" Fill="Yellow" /> 
     </GridView> 

ありがとう!

答えて

3

GridViewItemのテンプレートを抽出すると、ハードコードされた値(4pt余白、40x40パスなど)があることがわかります。これを回避するには、テンプレートを変更する必要がありますが、ハードコードすることができますアイテムの寸法それらを小さくする - ちょうどあなたが目に見えない選択チェックマークでOKであることを確認してください:

<GridView 
     Margin="120,80,0,0" 
     SelectionMode="Multiple"> 
     <GridView.ItemsPanel> 
      <ItemsPanelTemplate> 
       <VirtualizingStackPanel 
        Orientation="Horizontal" /> 
      </ItemsPanelTemplate> 
     </GridView.ItemsPanel> 
     <GridView.ItemContainerStyle> 
      <Style 
       TargetType="GridViewItem"> 
       <Setter 
        Property="HorizontalAlignment" 
        Value="Center" /> 
       <Setter 
        Property="VerticalAlignment" 
        Value="Center" /> 
       <Setter 
        Property="Width" 
        Value="20" /> 
       <Setter 
        Property="Height" 
        Value="20" /> 
       <Setter 
        Property="Padding" 
        Value="0" /> 
       <Setter 
        Property="Margin" 
        Value="0" /> 
      </Style> 
     </GridView.ItemContainerStyle> 
     <Rectangle 
      Height="10" 
      Width="10" 
      Fill="Red" /> 
     <Rectangle 
      Height="10" 
      Width="10" 
      Fill="Orange" /> 
     <Rectangle 
      Height="10" 
      Width="10" 
      Fill="Blue" /> 
     <Rectangle 
      Height="10" 
      Width="10" 
      Fill="Green" /> 
     <Rectangle 
      Height="10" 
      Width="10" 
      Fill="Yellow" /> 
    </GridView> 
+0

私は、大きな項目がトリミングされたでしょう引き起こし、ハードコードにサイズを望んでいません。 Blendを使ってテンプレートを抽出して、それがどうなるかを教えてくれます。ありがとう! – Carlo

+3

どうしたの? –

関連する問題