سؤال

I am writing a Visual Studio 2012 extension that defines several sub-menus to go in two existing Visual Studio context menus. The sub-menu items appear to work correctly except for one thing:

Until the first menu item in my package is clicked, the state of each menu item is its default state depending on its definition in the VSCT file. That works fine for menu items that are always enabled, but some menu items should be enabled or disabled based on certain changing conditions. After the package is sited, their states are set correctly, but how can I get the states to be set correctly before the first item is clicked?

There is no default state that works in my solution. The conditions might be true or false the first time my menus appear.

If you have a solution for this, or know where this has been addressed in a tutorial somewhere, I would appreciate your help.

هل كانت مفيدة؟

المحلول

I finally discovered the answer to my question at MSDN in an article called How to: Autoload a VSPackage. The "trick" is to set the ProvideAutoLoadAttribute on the package class that's created for the project. Here is the declaration for one of the projects I am working on:

[InstalledProductRegistration("#110", "#112", "1.0", IconResourceID = 400)]
[ProvideMenuResource("Menus.ctmenu", 1)]
[ProvideAutoLoad("{f1536ef8-92ec-443c-9ed7-fdadf150da82}")]
[Guid(GuidList.guidXamlHelpmeetPkgString)]
public sealed class XamlHelpmeetPackage : Package
{ ...

The third line is all that I added to make the otherwise working extension load early rather than on demand.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top