locked
VSIX ToolWindow does not set background for Dark Theme correctly. RRS feed

  • Question

  • I am also having trouble getting my ToolWindow to set the Background color of the Dark theme.  I appear to be passing the correct Brush to the WPF UserControl in my ToolWindow. The Window Title styles correctly but not the Background Color. How can I get the background color to match the theme?

        public class TestifyCoverageWindow : ToolWindowPane
        {
            private IVsUIShell5 _shell5;

            public TestifyCoverageWindow() :
                base(null)
            {
                Initialize();
                // Set the window title reading it from the resources.
                this.Caption = Resources.ToolWindowCodeCoverage;

                this.BitmapResourceID = 301;
                this.BitmapIndex = 1;
                var themeRespourceKey = new ThemeResourceKey(new System.Guid("624ed9c3-bdfd-41fa-96c3-7c824ea32e3d"), "ToolWindowBackground", 0);
                var themeColor = VsColors.GetThemedWPFColor(_shell5, themeRespourceKey);
                var colorBrush = new System.Windows.Media.SolidColorBrush(themeColor);
                base.Content = new SummaryViewControl(this, colorBrush);
              
            }
            protected override void Initialize()
            {
                _shell5 = Microsoft.VisualStudio.Shell.Package.GetGlobalService(typeof(SVsUIShell)) as IVsUIShell5;

            }

    Then in my ViewModel I do this...

            private void BuildCoverageViewModel()
            {
                _coverageViewModel = GetSummaries(_context);
                if (_coverageViewModel.Modules.Count > 0)
                {
                    this.Dispatcher.Invoke((Action)(() =>
                    {
                        this.Background = _brush;
                        base.Background = _brush;
                        treeGrid.Background = _brush;
                        base.DataContext = _coverageViewModel;
                      
                        treeGrid.DataContext = _coverageViewModel;
                     
                    }));
                }
                else
                {
                    base.Content = "Waiting for Solution to be Built";
                }
            }

    Monday, December 21, 2015 7:22 PM

Answers

  • Hi GoSouthward,

    Tested set background code in my control. It could works fine.

    this.Dispatcher.Invoke((Action)(() =>
    {
        this.Background = new SolidColorBrush(Colors.Blue);
    
    }));

    You could set a breakpoint on this line of code and check whether it is excuted or not.

    this.Background = _brush;
    Best Regards,
    Li Wang

    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by GoSouthward Wednesday, December 23, 2015 12:29 PM
    Wednesday, December 23, 2015 5:54 AM

All replies

  • Hi GoSouthward,

    Window title use the default style of Visual Studio, It doesn't allow us to change its background.

    Best Regards,
    Li Wang


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, December 22, 2015 2:32 AM
  • Hi, thanks for your reply, to clarify, I am trying to change the background of the whole ToolWindow. The Title and items in the TreeView are styled correctly.


    • Edited by GoSouthward Tuesday, December 22, 2015 11:51 AM
    Tuesday, December 22, 2015 11:51 AM
  • Hi GoSouthward,

    Tested set background code in my control. It could works fine.

    this.Dispatcher.Invoke((Action)(() =>
    {
        this.Background = new SolidColorBrush(Colors.Blue);
    
    }));

    You could set a breakpoint on this line of code and check whether it is excuted or not.

    this.Background = _brush;
    Best Regards,
    Li Wang

    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by GoSouthward Wednesday, December 23, 2015 12:29 PM
    Wednesday, December 23, 2015 5:54 AM
  • Thank you, that helped. My WPF binding was broken. I was setting the background on the TreeViewItem, and I thought I needed to set the background on the ToolWindow, but I needed to set the background on the TreeView itself.
    Wednesday, December 23, 2015 12:28 PM