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?


<Window x:Class="WpfApplication1.Window1"
            <Style TargetType="Button">
                <Setter Property="Margin" Value="5" />
            <data:Records x:Key="records">
                <data:Record Name="Record 1" Content="Some Content 1" />
                <data:Record Name="Record 2" Content="Some Content 2" />

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

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>

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}"
                Width="{Binding RelativeSource={RelativeSource AncestorType={x:Type dg:DataGrid}}, Path=CellsPanelHorizontalOffset}"
                Template="{StaticResource SelectAllButtonTemplate}"

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:

    <Style TargetType="Button" />

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