2013-09-08 4 views
1

Je voudrais ajouter une bordure autour des éléments dans mon UniformGrid WPF. Ce que j'ai essayé:Comment ajouter une bordure aux cellules UniformGrid

<Window.Resources> 
    <DataTemplate x:Key="GridCell"> 
     <Border BorderBrush="DarkGray" BorderThickness="5"></Border> 
    </DataTemplate> 
</Window.Resources> 

... et ...

<UniformGrid Name="grid"> 
    <ItemsControl ItemTemplate="{StaticResource GridCell}"></ItemsControl> 
</UniformGrid> 

Il ne fonctionne pas (pas de frontière apparaît). Je voudrais avoir chaque enfant de UniformGrid (les boutons qui sont créés par programme, donc ils n'apparaissent pas ici) pour avoir une frontière. Il doit ressembler, eh bien, à une grille ... avec des lignes horizontales et verticales délimitant des lignes et des colonnes.

+0

Voir [ce] (http://stackoverflow.com/questions/8541607/assigning-border-to-every-grid-row) question, @Carlo réponse sur 'BorderGrid'. 'DataTemplate' suggère que son contenu soit connu à l'avance, je pense que dans ce cas ça ne marche pas. –

+0

je voudrais regarder dans ItemsContainerStyle –

Répondre

3
<Grid> 
     <ItemsControl ItemsSource="{Binding NumericalPatches}" > 
      <ItemsControl.ItemsPanel> 
       <ItemsPanelTemplate> 
        <UniformGrid Rows="7" Columns="7"/> 
       </ItemsPanelTemplate> 
      </ItemsControl.ItemsPanel> 
      <ItemsControl.ItemTemplate> 
       <DataTemplate> 
        <Border BorderBrush="DimGray" BorderThickness="3"> 
         <Grid> 
          <Grid.ColumnDefinitions> 
           <ColumnDefinition Width="Auto"/> 
           <ColumnDefinition Width="Auto"/> 
          </Grid.ColumnDefinitions> 
          <Grid.RowDefinitions> 
           <RowDefinition Height="Auto"/> 
           <RowDefinition Height="Auto"/> 
          </Grid.RowDefinitions> 

          <TextBlock Grid.Row="0" Grid.Column="0" Margin="5" Text="{Binding StringFormat=F4,Path=Red}" FontSize="14" Foreground="Red"/> 
          <TextBlock Grid.Row="0" Grid.Column="1" Margin="5" Text="{Binding StringFormat=F4,Path=Green}" FontSize="14" Foreground="Green"/> 
          <TextBlock Grid.Row="1" Grid.Column="0" Margin="5" Text="{Binding StringFormat=F4,Path=Blue}" FontSize="14" Foreground="Blue"/> 
          <TextBlock Grid.Row="1" Grid.Column="1" Margin="5" Text="{Binding StringFormat=F4,Path=Chroma}" FontSize="14" Foreground="White"/> 

         </Grid> 
        </Border> 
       </DataTemplate> 
      </ItemsControl.ItemTemplate> 
     </ItemsControl> 
    </Grid> 
Questions connexes