locked
Support for Themes in Visual Studio Extensions RRS feed

  • Question

  • Hi, 

    Wanted to know that if there is something out of the box that allows VS Extension writers to style their forms in a "theme aware" manner. 



    Wednesday, April 30, 2014 3:47 PM

All replies

  • Does 2015 support extensions handling themes any better? If it does, I can't find it.
    Wednesday, January 6, 2016 1:52 PM
  • Regarding theme support, it can be done but to do it properly requires that you provide control templates to theme all of the affected controls that you use.  I recently went through this exercise in my own extensions.  I've been meaning to document what I did as it works quite well and the implementation should be usable in pretty much any extension.  The theme support I've got covers most of the common controls.

    To get started, add the three source code files found here to your project: https://github.com/EWSoftware/VSSpellChecker/tree/master/Source/VSSpellChecker/Theme

    Add this file to your extension's .\Resources folder: https://github.com/EWSoftware/VSSpellChecker/blob/master/Source/VSSpellChecker/Resources/VisualStudioThemeResources.xaml

    See an example user control for how to apply the templates (details below): https://github.com/EWSoftware/VSSpellChecker/blob/master/Source/VSSpellChecker/Editors/Pages/DictionarySettingsUserControl.xaml

    Add the UserControl.Resources element and change the reference to VisualStudio.SpellChecker to your extension's assembly name.  For a window, use Window.Resources instead.  In both cases, set the background color on the user control/window using the Background property on the root UserControl/Window element.

    When you change the namespaces to suit your project, do so consistently throughout all of the files noted above.  There are a few quirks that you may run into but that should get you started.  Let me know if you have any other questions.

    Eric

    • Proposed as answer by EWoodruff Wednesday, January 6, 2016 4:38 PM
    Wednesday, January 6, 2016 4:38 PM
  • To be honest, that's a lot more involved than I can justify for this at the moment. Just setting the foreground colour of my ClassificationFormatDefinition to the same as the users "URL Hyperlink" would be enough.

    Currently I've got code along the lines of this

                    Guid textEditorGuid = new Guid(FontsAndColorsCategory.TextEditor);
    
                    if (fcStorage.OpenCategory(
                        textEditorGuid,
                        (int)__FCSTORAGEFLAGS.FCSF_LOADDEFAULTS | (int)__FCSTORAGEFLAGS.FCSF_READONLY) == VSConstants.S_OK)
                    {
                        string s = fcStorage.ToString();
    
                        ColorableItemInfo[] pInfo = new ColorableItemInfo[1];
                        if (fcStorage.GetItem("Keyword", pInfo) == VSConstants.S_OK)
                        {
                            Color col = new Color();
                            IVsFontAndColorUtilities util = ServiceProvider.GlobalProvider.GetService(typeof(SVsFontAndColorStorage)) as IVsFontAndColorUtilities;
                            if(util != null)
                                this.ForegroundColor = util.GetRGBOfEncodedColor(pInfo[0].crForeground, ;
                        }
    

    When using "Keyword" GetItem does something, but "URL Hyperlink" doesn't (and I've tried a few obvious alternatives). I've still to work out how to actually get a Color out of the ColorableItemInfo as well.

    It would have been nice if I could have just based by ClassificationFormatDefinition off of the Hyperlink definition, but can't see a way to do that, or get the Hyperlink classifier either.

    Wednesday, January 6, 2016 5:55 PM
  • The original message in this thread was about theming tool windows and forms.  You look like you're doing something with classifiers which is completely different so what I did won't apply in your case unless you have tool windows or forms shown by the extension.

    Eric

    Wednesday, January 6, 2016 8:33 PM
  • Yeah, I was hoping form support would include getting things like standard colours that I could also use, but I agree I should have started another post, which I've now done. Your links will probably be helpful in the future, so thanks again!

    I got my cludge working for "Keyword".. still working on getting "URL Hyperlink" colour though :).

    Thursday, January 7, 2016 5:55 PM