Why button style interferes with DataGrid headers?

Dec 10, 2008 at 11:13 AM
It seams that button style changes appearence of the DataGrid header.

I don't want to change buttons style but this DataGrid render is not acceptable.
How to fix this?

Screenshot

-----------------------------------------
<Window x:Class="WpfApplication1.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:dg="http://schemas.microsoft.com/wpf/2008/toolkit"
    xmlns:data="clr-namespace:WpfApplication1"
    Title="Window1">
    <Grid>
        <Grid.Resources>
            <Style TargetType="Button">
                <Setter Property="Margin" Value="5" />
            </Style>
            <data:Records x:Key="records">
                <data:Record Name="Record 1" Content="Some Content 1" />
                <data:Record Name="Record 2" Content="Some Content 2" />
            </data:Records>
        </Grid.Resources>

        <dg:DataGrid ItemsSource="{StaticResource records}"/>
    </Grid>
</Window>

-----------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Collections.ObjectModel;

namespace WpfApplication1
{
    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>
    public partial class Window1: Window
    {
        public Window1( )
        {
            InitializeComponent( );
        }
    }

    public class Record
    {
        public string Name { get; set; }
        public string Content { get; set; }
    }

    public class Records: ObservableCollection<Record>
    {
    }
}

Coordinator
Dec 10, 2008 at 1:46 PM
If you absolutely want this implicit style for your Grid, then you can ignore the implicit style in the DataGrid by updating DataGrid's controltemplate so the left corner button does not use your implicit style. 

...
<!--Left Column Header Corner -->
<Button Command="{x:Static dg:DataGrid.SelectAllCommand}"
                Style="{x:Null}"
                Width="{Binding RelativeSource={RelativeSource AncestorType={x:Type dg:DataGrid}}, Path=CellsPanelHorizontalOffset}"
                Template="{StaticResource SelectAllButtonTemplate}"
                Focusable="false"
...

An alternative is to change the scope of your implicit button style so DataGrid does not get it's value.
Dec 10, 2008 at 4:02 PM
Thanks. I think overriding Button style inside DataGrid is fine:

<Grid.Resources>
    <Style TargetType="Button" />
</Grid.Resources>

PS How did you get color highlight in your post? When I copy from studio it doesn't keep it.