NoWar
NoWar

Reputation: 37633

How to set height of the UWP Toolkit DataGrid row?

Using this MSDN tip I try to set height of the UWP Toolkit DataGrid row but no success.

https://learn.microsoft.com/en-us/windows/communitytoolkit/controls/datagrid_guidance/sizing_options

Sizing Rows and Row Headers DataGrid Rows By default, a DataGrid row's Height property is set to Double.NaN ("Auto" in XAML), and the row height will expand to the size of its contents. The height of all rows in the DataGrid can be specified by setting the DataGrid.RowHeight property. Users cannot change the row height by dragging the row header dividers.

I have tried folowing

  1. RowHeight="12" of the DataGrid
  2. DataGridTemplateColumn -> TextBlock Height="12"

Nothing works.

XAML

 <toolkit:DataGrid ItemsSource="{x:Bind TripEvents, Mode=OneWay}"
                   x:Name="dataGridTripEvents"
                   HeadersVisibility="Column"
                   SelectionMode="Single"  
                   GridLinesVisibility="Horizontal"   
                   RowHeight="12">
  <toolkit:DataGrid.Columns>             
    <toolkit:DataGridTemplateColumn Header="#">
       <toolkit:DataGridTemplateColumn.CellTemplate>
          <DataTemplate>
             <TextBlock Height="12" FontSize="10" Text="{Binding NumberByOrder, Mode=OneWay}" Margin="2,2,2,2" Padding="2,2,2,2">
             </TextBlock>
          </DataTemplate>                                                
       </toolkit:DataGridTemplateColumn.CellTemplate>
    </toolkit:DataGridTemplateColumn>
 </toolkit:DataGrid.Columns>
</toolkit:DataGrid>

Please help! Thank you!

Upvotes: 1

Views: 763

Answers (1)

Nico Zhu
Nico Zhu

Reputation: 32775

Please check source code here, the min height is 32, if value you set less than 32, it will not effect.

<Style TargetType="local:DataGridCell">
        <Setter Property="Background" Value="{ThemeResource DataGridCellBackgroundBrush}"/>
        <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
        <Setter Property="VerticalContentAlignment" Value="Stretch"/>
        <Setter Property="FontSize" Value="15"/>
        <Setter Property="MinHeight" Value="32"/>
        <Setter Property="IsTabStop" Value="False"/>

Upvotes: 1

Related Questions