AvaloniaUI / Avalonia

Develop Desktop, Embedded, Mobile and WebAssembly apps with C# and XAML. The most popular .NET UI client technology
https://avaloniaui.net
MIT License
25.36k stars 2.2k forks source link

Cannot set Margin/Padding/Alignment for DataGridTextColumn.Header #16488

Closed postrondev closed 2 months ago

postrondev commented 2 months ago

Describe the bug

I consider this as bug, not having control over content. Padding is forced to be 12,0,0,0. Why fixed? Alignment is set to center. Why fixed.

To Reproduce

<Window xmlns="https://github.com/avaloniaui"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
        x:Class="BCF.TimeRecUI.OverviewWindow"
        Title="OverviewWindow">
    <Border BorderThickness="3" BorderBrush="Green" CornerRadius="3" Padding="0">
        <DataGrid>
            <DataGrid.Columns>
                <DataGridTextColumn Header="26.07.2024" Width="80"  />
                <DataGridTextColumn Header="Last Name"/>
            </DataGrid.Columns>         
        </DataGrid>
    </Border>
</Window>

App.Xaml

<Application xmlns="https://github.com/avaloniaui"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             x:Class="BCF.TimeRecUI.App"
             RequestedThemeVariant="Default">
             <!-- "Default" ThemeVariant follows system theme variant. "Dark" or "Light" are other available options. -->

    <Application.Styles>
        <FluentTheme />
        <StyleInclude Source="avares://Avalonia.Controls.DataGrid/Themes/Fluent.xaml" />
    </Application.Styles>
    <Application.Resources>
        <FontFamily x:Key="InconsolataFont">avares://BCF.TimeRecUI/Resources/Fonts/Inconsolata/Inconsolata-Bold.ttf#Inconsolata</FontFamily>
        <x:Double x:Key="DataGridSortIconMinWidth">12</x:Double>
    </Application.Resources>
</Application>

Expected behavior

I see no reason to forbid developers to make there own choices how to style there ui.

PLEASE!!!!!!!!!!!!!!!!!!!!!!!!!!

Do NOT answer with snippets nobody knows where or how to use. I have spend hours with nonsense answers without any context.

Avalonia version

11.1.0

OS

No response

Additional context

No response

timunie commented 2 months ago

I honestly don't see a bug here? From the source it looks like a style should be able to override the margin. So what's your expectation here?

Off topic: Also please be kind in your comments. People try to help you in their free time. So even if the answer doesn't help you, it's still worth a thank you imo.

maxkatz6 commented 2 months ago

Padding is forced to be 12,0,0,0. Why fixed? Alignment is set to center. Why fixed.

It's not "fixed" - you can edit it. What kind of "un-fixed" do you expect? As mentioned above, you can fully or partially restyle DataGrid.

Do NOT answer with snippets nobody knows where or how to use.

I have to, because otherwise I have no clue what you even expect. Even more, other developers might find this issue looking for an actual snippet.

<DataGrid>
    <DataGrid.ColumnHeaderTheme>
        <ControlTheme TargetType="DataGridColumnHeader" BasedOn="{StaticResource {x:Type DataGridColumnHeader}}">
            <Setter Property="Padding" Value="0" />
            <Setter Property="VerticalContentAlignment" Value="Top" />
        </ControlTheme>
    </DataGrid.ColumnHeaderTheme>
</DataGrid>

You can reuse this, apply globally on all headers or use in a single data grid.