Home > Back-end >  WPF DataGrid Cell Content Size - Material Design
WPF DataGrid Cell Content Size - Material Design

Time:06-24

I'm using WPF Material Design. It's a great library and really enjoying it. However, something that's a problem for me at this stage is the cell contents of a DataGrid does not fill the entire cell. For starters, it looks ugly. But the bigger problem is if you click on the cell next to the control which is still inside the cell it does not edit the control. You need to click on the control itself.

Any idea how I can get the control to fill the entire cell with a very small padding ?

Textbox Cell

Combobox Cell

Datagrid Code

<DataGrid Name="gridComponents" AutoGenerateColumns="False" CanUserAddRows="False" CanUserDeleteRows="False" ItemsSource="{Binding Path=MassBalance.DefinedComponents}">

    <DataGrid.Columns>
        <DataGridTextColumn Binding="{Binding Path=ComponentName}" Header="Component Name" IsReadOnly="True" />
        <DataGridTextColumn Binding="{Binding Path=Formula}" Header="Formula" />
        <DataGridComboBoxColumn ItemsSource="{Binding Source={StaticResource phaseEnum}}" SelectedItemBinding="{Binding Path=ComponentPhase}" Header="Phase"  ></DataGridComboBoxColumn>
        <DataGridTextColumn Binding="{Binding Path=Density}" Header="Density" />
        <DataGridTextColumn Binding="{Binding Path=MolecularWeight}" Header="Molecular Weight" IsReadOnly="True" />
    </DataGrid.Columns>
</DataGrid>

CodePudding user response:

Any idea how I can get the control to fill the entire cell with a very small padding ?

Use the DataGridAssist.CellPadding attached property:

xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
...
<DataGrid materialDesign:DataGridAssist.CellPadding="0" .../>
  • Related