0

I have a datagrid in one of my WPF application where I am showing some data from an XML file. Now there are rows which are kind of a headers. I want to show those rows with colspan, so that it occupies the whole row. I have tried the below code but it is not working.

<DataGrid.RowStyle>
  <Style TargetType="DataGridRow">    
      <Style.Triggers>
         <DataTrigger Binding="{Binding Type}" Value="BorderCheck">
              <Setter Property="Grid.ColumnSpan" Value="6" />
         </DataTrigger>                        
      </Style.Triggers>
  </Style>
</DataGrid.RowStyle>
Joy
  • 1,609
  • 3
  • 16
  • 28
  • 1
    Why not use grouping? check this out: http://dotnetpattern.com/wpf-datagrid-grouping – Rom Oct 18 '16 at 11:53

1 Answers1

-2

There are 2 things if you need column span to all the rows there's no point adding extra columns if you need column span to particular rows you need set it at the row level which should be the element you want to expand to other columns like below

<Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="50"/>
            <RowDefinition Height="100"/>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="5*" />
            <ColumnDefinition Width="5*" />
        </Grid.ColumnDefinitions>
        <Label  Grid.Row="0" Grid.Column="0" FontSize="20" >Name</Label>
        <TextBox Grid.Row="1" Grid.ColumnSpan="2" BorderThickness="5" />
    </Grid>

Ouputwill be like this

Krishna
  • 1,945
  • 1
  • 13
  • 24
  • The problem is I am using DataGrid not Grid. In DataGrid I need to have this feature depending on the databindings. I mean it should be dynamic. i.e. If the row type is something then only it should be columnspan – Joy Oct 18 '16 at 12:06