Share via


Reverse Engineering Styles in Avalon Using System.Windows.Serialization.Parser

A key tenet of Avalon is "lookless" controls: a button should simply be the idea of a button, not the actual button -- very Platonic, really.  Now, the platform would not be very useful if all we provided was the idea of a button, so each content control does have a default style.  Here's a nifty Avalon trick for finding out how the default styles were written, which can be very useful if you are looking to understand how to override that style and replace it with your own:

System.Windows.Controls.

Control t = new System.Windows.Controls.TextBox();
Style s = t.Style;
using (StreamWriter sw = new StreamWriter(@"C:\Styles\TextBoxDefaultStyle.xaml"))
{
sw.WriteLine(System.Windows.Serialization.Parser.SaveAsXml(s));
}Note that you could replace TextBox with any Avalon control.

Comments

  • Anonymous
    July 22, 2005
    Let's just hope that people USE the default styles. A common fear is that, since Avalon makes it easy to create such fancy UIs, that they will all be completely different and inconsistent. Hopefully developers will keep this in mind and use the defaults (which I assume are based on the user's visual style).
  • Anonymous
    July 25, 2005
    This looks like an useful tip - Avalon controls have a default style and you can get that information...
  • Anonymous
    February 10, 2006
    I decided to try and improve the look of my Sandbox3D by opening and styling it in Expression Interactive...
  • Anonymous
    December 18, 2006
    PingBack from http://netfx30.wordpress.com/2006/12/19/default-wpf-control-templates/