Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fluent2 datagrid cell style based on DefaultDataGridCellStyle #10351

Open
johanneskopf opened this issue Jan 28, 2025 · 3 comments
Open

Fluent2 datagrid cell style based on DefaultDataGridCellStyle #10351

johanneskopf opened this issue Jan 28, 2025 · 3 comments
Labels
Investigate Requires further investigation by the WPF team. Win 11 Theming

Comments

@johanneskopf
Copy link

johanneskopf commented Jan 28, 2025

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.

@himgoyalmicro
Copy link
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?

@johanneskopf
Copy link
Author

johanneskopf commented Jan 29, 2025

@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.

@dotnet-policy-service dotnet-policy-service bot removed the 📭 waiting-author-feedback To request more information from author. label Jan 29, 2025
@miloush
Copy link
Contributor

miloush commented Jan 29, 2025

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.

@dipeshmsft dipeshmsft added Investigate Requires further investigation by the WPF team. and removed Needs minimal repro project labels Jan 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Investigate Requires further investigation by the WPF team. Win 11 Theming
Projects
None yet
Development

No branches or pull requests

4 participants