1

I have made a new Visual Studio extension with a tool window as described by Microsoft here https://learn.microsoft.com/en-us/visualstudio/extensibility/creating-an-extension-with-a-tool-window?view=vs-2019

I have not made any changes to code generated by Visual Studio, but I am getting two warnings:

The resource "{x:Static vsshell:VsBrushes.WindowKey}" could not be resolved.    
The resource "{x:Static vsshell:VsBrushes.WindowTextKey}" could not be resolved.    

due to the two lines shown in the following screen shot.

enter image description here

There is a very similar to the question here

VS2010 to VS2012 ToolWindow XAML Reference VsBrushes

except that that question references Visual Studio 2012. I am using Visual Studio 2019, so there might have been some change in the meantime.

The answers to that question did not work for me.

Can anyone explain this behavior? It seems odd that the automatically generated code should contain these warnings.

Phil Jollans
  • 3,605
  • 2
  • 37
  • 50

1 Answers1

2

Why the warning occurs:

See Difference between DynamicResource and StaticResource.The Tool Window item uses DynamicResources, so the resource can be set and changed in runtime.

And the WindowsKey and WindowsTextKey comes from VsBrushes class, these two color resources can't be accessed in designer-time, instead they can be accessed in runtime. That's why the Tool Window control works well after installing the .vsix while vs show the two warnings.

In addition:

If we change the DynamicResource to StaticResource, the warning would become error. The default value vsshell:VsBrushes.WindowKey in the template only can be accessed in runtime,so the developer team set the DynamicResource by default.

I think it's by design and the warning actually can be seen as a message: Possible notFoundResource, please take care! So we can just ignore it.

To remove the warning:

As i said, it's just a message to tell us there is possibility the resource can't be resolved since the designer can't access the resource vsshell:VsBrushes.WindowKey in "designer-time". Why not set the color to a system color which we can access when designing the control.

Actually we are developing a Window COntrol, of course we can change the color of the control to make it better.(UI-design?) So for me, I change the two resource to SystemResource which can be accessed in designer-time then the warnings went away:

Background="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"
Foreground="{DynamicResource {x:Static SystemColors.MenuBarBrushKey}}"
LoLance
  • 25,666
  • 1
  • 39
  • 73