private IDesignerHost GetDesignerHost(Window window)
{
// In most instances, the IDesignerHost can be retrieved
// directly off of the window object.
IDesignerHost designerHost = window.Object as IDesignerHost;
if (designerHost != null)
return designerHost;
// webform designer though, is a special case
HTMLWindow htmlWindow = window.Object as HTMLWindow;
if (htmlWindow != null)
{
// make sure current tab is the designer tab
htmlWindow.CurrentTab = vsHTMLTabs.vsHTMLTabsDesign ;
IOleServiceProvider oleSP = (IOleServiceProvider)htmlWindow.CurrentTabObject;
Microsoft.VisualWebDeveloper.Interop.WebDeveloperPage.DispDesignerDocument d = htmlWindow.CurrentTabObject as Microsoft.VisualWebDeveloper.Interop.WebDeveloperPage.DispDesignerDocument;
Guid guidVsMDDDesigner = new Guid("7494682A-37A0-11d2-A273-00C04F8EF4FF");
IntPtr ptr;
oleSP.QueryService(ref guidVsMDDDesigner, ref guidVsMDDDesigner, out ptr);
if (ptr != IntPtr.Zero)
{
IServiceProvider dotnetSP = (IServiceProvider)Marshal.GetObjectForIUnknown(ptr);
Marshal.Release(ptr);
designerHost = (IDesignerHost)dotnetSP.GetService(typeof(IDesignerHost));
}
}
return designerHost;
}