12

I am looking to change the style of a control but I basically want to copy part of a default style. Does anyone know how I can figure out what the default style of a control is?

In my case I am wanting to make the column headers in a DataGrid go blue on mouse over like the row headers do.

H.B.
  • 166,899
  • 29
  • 327
  • 400
KrisTrip
  • 4,943
  • 12
  • 55
  • 74
  • 1
    possible duplicate of [Control template for existing controls in WPF](http://stackoverflow.com/questions/1559261/control-template-for-existing-controls-in-wpf) – H.B. Jan 31 '12 at 02:01

2 Answers2

9

You can find some templates that are very close to the defaults on this MSDN site

Another alternative is to get a copy of Expression Blend and use it to make a copy of the default style, however Blend isn't free

Rachel
  • 130,264
  • 66
  • 304
  • 490
  • The link you gave doesn't seem to actually have the default styles. It gives an example of how to set the styles (at least for DataGrid) but it isn't the default. I do have a copy of Blend, how would I use Blend to get a copy of the DataGrid template? – KrisTrip Jan 31 '12 at 15:07
  • 1
    The link contains the default templates, however the colors shown for the DataGrid are customized and don't pull from the theme-specific colors like they usually do. You'd have to set them up yourself. If you're interested in only styling one part of the DataGrid I'd suggest looking at [this link](http://blogs.msdn.com/b/jaimer/archive/2009/01/20/styling-microsoft-s-wpf-datagrid.aspx), or you can use [this badly named page](http://dotnet.dzone.com/news/wpf-kid-stuff-extracting) to see an example of using Blend to make a copy of the style. – Rachel Jan 31 '12 at 16:18
  • any idea what the default colors are? Are those listed somewhere? – KrisTrip Jan 31 '12 at 17:30
  • 3
    @KrisTrip They are different depending on what theme you are using, and the OS settings, but you can find the colors for the standard themes [here](http://blogs.msdn.com/b/wpf/archive/2010/11/30/systemcolors-reference.aspx). You can bind a color to a system brush by using the following syntax: `Foreground="{x:Static SystemColors.ControlTextBrush}"` – Rachel Jan 31 '12 at 17:57
  • 1
    Today Blend is free inside Visual Studio 2013 Community Edition – white.zaz Dec 04 '14 at 13:23
6

Contrary to what Rachel says, the link she provides does not provide the default templates.

I have seen using System.Windows.Markup.XamlWriter.Save(myObject.Template) that the default templates are completely different from what that site shows.

Anonymous Coward
  • 596
  • 1
  • 5
  • 5
  • You are correct, the first link I posted is not the exact defaults, although for most purposes I find they are fairly close. I've updated my answer to clarify that, thanks :) – Rachel Dec 06 '14 at 17:30
  • After much searching, this is the only way that worked for ToggleButton. Even the XAML designer's `(right click component) > Edit Template > Edit a Copy` feature gives a bad template (the toggle button doesn't toggle). Thank you! – Vimes Sep 30 '16 at 05:22