From 185ae7e2b0d6705e0a6343a3c55591763f8adee5 Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Fri, 5 Sep 2008 10:51:28 +0000 Subject: [PATCH] Enable WPF designer only for Window and UserControl. git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/3.0@3497 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61 --- .../WpfDesign.AddIn/Src/WpfDisplayBinding.cs | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.AddIn/Src/WpfDisplayBinding.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.AddIn/Src/WpfDisplayBinding.cs index d72180e4c6..11148fcc19 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.AddIn/Src/WpfDisplayBinding.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.AddIn/Src/WpfDisplayBinding.cs @@ -8,7 +8,9 @@ using System; using System.IO; using ICSharpCode.SharpDevelop; +using ICSharpCode.SharpDevelop.Dom; using ICSharpCode.SharpDevelop.Gui; +using System.Xml; namespace ICSharpCode.WpfDesign.AddIn { @@ -35,7 +37,23 @@ namespace ICSharpCode.WpfDesign.AddIn public bool CanAttachTo(IViewContent content) { - return Path.GetExtension(content.PrimaryFileName).Equals(".xaml", StringComparison.OrdinalIgnoreCase); + if (Path.GetExtension(content.PrimaryFileName).Equals(".xaml", StringComparison.OrdinalIgnoreCase)) { + IEditable editable = content as IEditable; + if (editable != null) { + try { + XmlTextReader r = new XmlTextReader(new StringReader(editable.Text)); + r.XmlResolver = null; + r.WhitespaceHandling = WhitespaceHandling.None; + while (r.NodeType != XmlNodeType.Element && r.Read()); + + if (r.LocalName == "Window" || r.LocalName == "UserControl") + return true; + } catch (XmlException) { + return false; + } + } + } + return false; } public IViewContent[] CreateSecondaryViewContent(IViewContent viewContent)