I have an extensibility project in Visual Studio and I need to use the event triggered when I change from one window to another in the visual studio editor, my problem:
I created a Tool Window that display some diagram, that diagram depend of an editable file, when I save the editable file my tool window updates the information, but when there is more than one editable file opened and I switch between them I want that the tool window updates the information as well. So:
I want to get the event triggered when I switch between windows, file or documents in Visual Studio so I can use it to execute the update code of my tool window. Is there something I can do about it?
I just read this question here but I didn't find a solution in there: Are there any document window focus events?
You can subscribe to the EnvDTE.WindowEvents.WindowActivated event:
using EnvDTE;
using Microsoft.VisualStudio.Shell;
private class MyClass
{
private DTE dte;
public MyClass()
{
dte = Package.GetGlobalService(typeof(EnvDTE.DTE)) as EnvDTE.DTE;
dte.Events.WindowEvents.WindowActivated += OnWindowActivated;
}
private void OnWindowActivated(Window gotFocus, Window lostFocus)
{
throw new NotImplementedException();
}
}
See for example the 1. Display document path of the active window in the status bar sample code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With