Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why Width="*" doesn't work for columns in DataGrid located in RowDetailsTemplate

If I set widths of DataGrid (located in RowDetailesTemplate) columns using "*" - columns scaling doesn't work

<DataGrid>
...
<DataGrid.RowDetailsTemplate>
   <DataTemplate>
      <DataGrid Margin="10" Height="100">
         <DataGrid.Columns>
            <DataGridTextColumn Header="header A" Width="3*" />
            <DataGridTextColumn Header="header B" Width="2*" />
            <DataGridTextColumn Header="header C" Width="*" />
         </DataGrid.Columns>
      </DataGrid>
    </DataTemplate>
</DataGrid.RowDetailsTemplate>
</DataGrid>

enter image description here

but if I replace DataGrid by Grid and set it's columns width using "*" scailing works

<Grid Margin="5" Height="100">
   <Grid.ColumnDefinitions>
      <ColumnDefinition Width="3*"></ColumnDefinition>
      <ColumnDefinition Width="2*"></ColumnDefinition>
      <ColumnDefinition Width="*"></ColumnDefinition>
   </Grid.ColumnDefinitions>

   <TextBlock Text="header A" Background="LightGray" TextAlignment="Center" HorizontalAlignment="Stretch"></TextBlock>
   <TextBlock Text="header B" Grid.Column="1" TextAlignment="Center" HorizontalAlignment="Stretch"></TextBlock>
   <TextBlock Text="header C" Grid.Column="2" Background="LightGray" TextAlignment="Center" HorizontalAlignment="Stretch"></TextBlock>
</Grid>

enter image description here

how to fix DataGrid scaling ?

solution:

<DataGrid HorizontalScrollBarVisibility="Disabled">
...
<DataGrid.RowDetailsTemplate>
...
</DataGrid.RowDetailsTemplate>
</DataGrid>
like image 890
user1897059 Avatar asked Dec 22 '12 13:12

user1897059


People also ask

How do I make DataGrid read only?

To make a column read-only programmaticallySet the DataGridViewColumn. ReadOnly property to true .

What is WPF DataGrid?

A DataGrid is a control that displays data in a customizable grid. It provides a flexible way to display a collection of data in rows and columns. The hierarchical inheritance of DataGrid class is as follows −


1 Answers

It is just a guess based on this question.

Set ScrollViewer.HorizontalScrollBarVisibility="Disabled".

like image 178
Ramin Avatar answered Sep 28 '22 04:09

Ramin