shi's profile白驹过隙PhotosBlogListsMore Tools Help

Blog


    June 08

    Dump control's default Style

        Windows SDK provides sample styles for WPF common controls. (located at WinFX Development / Windows Presentation Foundation / Controls / Control Customization / Overviews). But it's not the real style. If you want to see the actual style of WPF controls, please try the following code (We use button as sample here):
     
                Style style = FindResources(typeof(Button)) as Style; //Get button's default Style
                if (style != null)
                {
                    XmlWriterSettings settings = new XmlWriterSettings();
                    settings.Indent = true;
                    settings.IndentChars = new string(' ', 4);
                    StringBuilder strbuild = new StringBuilder();
                    XmlWriter xmlwrite = XmlWriter.Create(strbuild, settings);
                    XamlWriter.Save(style, xmlwrite);//Use XamlWriter to dump the style
                    return strbuild.ToString();
                }
     
     
        The basic idea is to use FindResources(typeof(<controlname>)) to get the control's default style, then use XamlWriter to dump the style to XAML code.

    Comments (1)

    Please wait...
    Sorry, the comment you entered is too long. Please shorten it.
    You didn't enter anything. Please try again.
    Sorry, we can't add your comment right now. Please try again later.
    To add a comment, you need permission from your parent. Ask for permission
    Your parent has turned off comments.
    Sorry, we can't delete your comment right now. Please try again later.
    You've exceeded the maximum number of comments that can be left in one day. Please try again in 24 hours.
    Your account has had the ability to leave comments disabled because our systems indicate that you may be spamming other users. If you believe that your account has been disabled in error please contact Windows Live support.
    Complete the security check below to finish leaving your comment.
    The characters you type in the security check must match the characters in the picture or audio.

    To add a comment, sign in with your Windows Live ID (if you use Hotmail, Messenger, or Xbox LIVE, you have a Windows Live ID). Sign in


    Don't have a Windows Live ID? Sign up

    Picture of Anonymous
    les wrote:
    theres a tool available to get the style see blog blogs.msdn.com\llobo
    July 22

    Trackbacks

    The trackback URL for this entry is:
    http://baishi9411.spaces.live.com/blog/cns!9198D7311EDA82B4!139.trak
    Weblogs that reference this entry
    • None