How can you detect a XAML designer window in a VSPackage

32 views Asked by At

In my VSPackage I have an event handler for the WindowActivated event on the EnvDTE.WindowEvents interface.

In my code I check whether the activated window is WinForms designer with (in VB.NET)

If TypeOf GotFocus.Object Is IDesignerHost Then
  ...
End if

or an ASP designer window with

If TypeOf GotFocus.Object Is EnvDTE.HTMLWindow Then
  ...
End if

What is the best way to detect when a XAML designer window is activated?

Of course, I can check the file extension in the caption (GotFocus.Caption), but I wondered if there was a better way.

1

There are 1 answers

0
Ed Dore On

File extension probably isn't a good idea because you can open a .XAML file with the stock code editor as well :-)

Easiest way I can think of, would be to leverage the IVsMonitorSelection service.

Call GetCmdUIContextCookie with the the XAML Designer context guid {e9b8485c-1217-4277-b6d6-c825a5ac1968} (found with the Component Diagnostics extension ), and then call IsCmdUIContextActive to determine if the designer is activated.