0
votes

I want to apply the following style to certain cells of my grid:

<Border BorderBrush="#808080" BorderThickness="1,1,0,0" Grid.Column="3" >
    <Border BorderBrush="#404040" BorderThickness="1,1,0,0" Width="Auto">
        <Border BorderBrush="#FFFFFF" BorderThickness="0,0,1,1" Width="Auto">
            <Border BorderBrush="#DCE6F4" BorderThickness="0,0,1,1" Width="Auto">
            </Border>
        </Border>
    </Border>
</Border>

Right now i specify the cell in the first line Grid.Colum="3". However to do this for all cells I have to copy paste this like 20 times. Is there any short way to apply my style to all controls or cells of my choice (for example cell 1, , 7, 9 or label1, label 9 and label10?

I am a newbie in wpf, please be gentle :)

1
What do you want to place inside the boder? Only labels? - Flat Eric
The basic Grid class doesn't really have 'Cells', just rows and columns. Your might be able to do this with an ItemsControl but that all depends on what you want inside and how you want the layout. - Henk Holterman

1 Answers

2
votes

Assuming you want to place labels inside the grid you could create a ControlTemplate and assign it to the labels you want with Template="{StaticResource BorderLabel}":

<Grid Margin="5">
  <Grid.ColumnDefinitions>
    <ColumnDefinition Width="*" />
    <ColumnDefinition Width="*" />
  </Grid.ColumnDefinitions>

  <Grid.Resources>
    <ControlTemplate TargetType="Label" x:Key="BorderLabel">
      <Border BorderBrush="#808080" BorderThickness="1,1,0,0" >
        <Border BorderBrush="#404040" BorderThickness="1,1,0,0" Width="Auto">
          <Border BorderBrush="#FFFFFF" BorderThickness="0,0,1,1" Width="Auto">
            <Border BorderBrush="#DCE6F4" BorderThickness="0,0,1,1" Width="Auto">
              <ContentControl Content="{TemplateBinding Content}" />
            </Border>
          </Border>
        </Border>
      </Border>
    </ControlTemplate>

  </Grid.Resources>

  <Label Grid.Column="0" Content="MyText" />
  <Label Grid.Column="1" Content="MyText" Template="{StaticResource BorderLabel}" />
</Grid>

And this is how it looks:

Result