Skip to content

Fluent2 datagrid cell style based on DefaultDataGridCellStyle #10351

Open

Description

@johanneskopf

Description

I want to adapt the .net 9 fluent theme's DefaultDataGridCellStyle so the grid cells do not look that cramped. Thus, I added a border and centered the cell's content:

<Style TargetType="DataGridCell" BasedOn="{StaticResource DefaultDataGridCellStyle}">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="DataGridCell">
                <Border Padding="8" Background="{TemplateBinding Background}">
                    <ContentPresenter VerticalAlignment="Center" />
                </Border>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

Using that code, I override the default ControlTemplate completely and loose existing functionality. Instead I want to add those changes to the existing template. How can I achieve this? Or is there an overall better way?

I need the dark and the light theme to work as they are supposed to.

Thanks in advance.

Activity

  1. himgoyalmicro commented on Jan 29, 2025

    @himgoyalmicro
    Contributor

    @johanneskopf Can you please share what all functionalities are you losing by using this style and can you please also share a sample repro?

  2. johanneskopf commented on Jan 29, 2025

    @johanneskopf
    Author

    @himgoyalmicro find the sample repro here: https://github.com/johanneskopf/sample-DefaultDataGridCellStyle-override
    This shows that after applying a custom ControlTemplate to the DataGridCells of my DataGrid, row highlighting no longer functions as intended.

    The issue is not about a specific feature lost though; it's about preserving all inherent framework functionalities. I aim to maintain the default behaviors while just adding a padding to each cell content and center it. Ideally it's future proof, i.e. I don't want to copy the whole ControlTemplate code of the default fluent style, as this might be changed in the future.

  3. removed
    📭 waiting-author-feedback
    on Jan 29, 2025
  4. miloush commented on Jan 29, 2025

    @miloush
    Contributor

    There is DataGrid.CellStyle and DataGridBoundColumn.ElementStyle. Setting Margin using cell style seems to be having an effect, although the margin is outside of cell borders, so depending on your design, it might not be helpful. Setting Padding doesn't do anything and that should be fixed in all the themes.

  5. added
    Investigate
    and removed on Jan 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    InvestigateWin 11 Theming

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions