none
Take out margins on DataGridTextColumn in WPF RRS feed

  • Question

  • Currenty I have a DataGrid like so

    <DataGrid Grid.Row="0" ItemsSource="{Binding ResultSet}" AutoGenerateColumns="False"
            SelectedItem="{Binding AValue, Mode=TwoWay}"
            CanUserAddRows="False" CanUserReorderColumns="True" CanUserDeleteRows="False"
            KeyboardNavigation.TabNavigation="Once"
            CanUserResizeColumns="True" CanUserSortColumns="True" SelectionMode="Single" MinHeight="300">
            <i:Interaction.Triggers>
                <i:EventTrigger EventName="SelectionChanged">
                    <i:InvokeCommandAction Command="{Binding SelectedCommand}"/>
                </i:EventTrigger>
            </i:Interaction.Triggers>
            <DataGrid.InputBindings>
                <MouseBinding MouseAction="LeftDoubleClick" Command="{Binding ViewDetailsCommand}"/>
            </DataGrid.InputBindings>
            <DataGrid.RowHeaderStyle>
                <Style TargetType="{x:Type DataGridRowHeader}">
                    <Setter Property="Content" Value="{StaticResource AResource}" />
                </Style>
            </DataGrid.RowHeaderStyle>
            <DataGrid.Columns>
                <DataGridTextColumn KeyboardNavigation.IsTabStop="False" IsReadOnly="True" Width="Auto" Header="{l:LocText SomeText}" Binding="{Binding ABinding1}"  />
                <DataGridTextColumn KeyboardNavigation.IsTabStop="False" IsReadOnly="True" Width="Auto" Header="{l:LocText SomeText1}" Binding="{Binding ABinding2}" />
            </DataGrid.Columns>
    </DataGrid>

    This is the style of the Column Header:

    <Style x:Key="AResource" TargetType="{x:Type DataGridColumnHeader}"
           BasedOn="{StaticResource MaterialDesignDataGridColumnHeader}">
        <Setter Property="Background" Value="#1c313a" />
    </Style>

    The thing is, each column has like some Margin, a left and right one so I can't put the columns almost together, I want to eliminate that Margin or whatever it is.

    enter image description hereAs you can see If I put the Column2 "Close" to Column1, then there is this sort of content that takes out the space of Column1, each column has this space.

    Im using MaterialDesign.

    Thursday, October 31, 2019 8:04 PM

All replies

  • Currenty I have a DataGrid like so

    <DataGrid Grid.Row="0" ItemsSource="{Binding ResultSet}" AutoGenerateColumns="False"
            SelectedItem="{Binding AValue, Mode=TwoWay}"
            CanUserAddRows="False" CanUserReorderColumns="True" CanUserDeleteRows="False"
            KeyboardNavigation.TabNavigation="Once"
            CanUserResizeColumns="True" CanUserSortColumns="True" SelectionMode="Single" MinHeight="300">
            <i:Interaction.Triggers>
                <i:EventTrigger EventName="SelectionChanged">
                    <i:InvokeCommandAction Command="{Binding SelectedCommand}"/>
                </i:EventTrigger>
            </i:Interaction.Triggers>
            <DataGrid.InputBindings>
                <MouseBinding MouseAction="LeftDoubleClick" Command="{Binding ViewDetailsCommand}"/>
            </DataGrid.InputBindings>
            <DataGrid.RowHeaderStyle>
                <Style TargetType="{x:Type DataGridRowHeader}">
                    <Setter Property="Content" Value="{StaticResource AResource}" />
                </Style>
            </DataGrid.RowHeaderStyle>
            <DataGrid.Columns>
                <DataGridTextColumn KeyboardNavigation.IsTabStop="False" IsReadOnly="True" Width="Auto" Header="{l:LocText SomeText}" Binding="{Binding ABinding1}"  />
                <DataGridTextColumn KeyboardNavigation.IsTabStop="False" IsReadOnly="True" Width="Auto" Header="{l:LocText SomeText1}" Binding="{Binding ABinding2}" />
            </DataGrid.Columns>
    </DataGrid>

    This is the style of the Column Header:

    <Style x:Key="AResource" TargetType="{x:Type DataGridColumnHeader}"
           BasedOn="{StaticResource MaterialDesignDataGridColumnHeader}">
        <Setter Property="Background" Value="#1c313a" />
    </Style>

    The thing is, each column has like some Margin, a left and right one so I can't put the columns almost together, I want to eliminate that Margin or whatever it is.

    enter image description hereAs you can see If I put the Column2 "Close" to Column1, then there is this sort of content that takes out the space of Column1, each column has this space.

    Im using MaterialDesign.


    Hi   Nicolas_Mendez, 

    It's seems duo to the Material Design itself. It will reserve some space for the following tips( Arrow, and text back)



    You can ask help from issue center to get some help.



    Best regards

    Yong Lu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, November 1, 2019 3:38 AM