diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.AddIn/Src/MyTypeFinder.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.AddIn/Src/MyTypeFinder.cs index 69ea707f72..e305610099 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.AddIn/Src/MyTypeFinder.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.AddIn/Src/MyTypeFinder.cs @@ -37,6 +37,15 @@ namespace ICSharpCode.WpfDesign.AddIn } return null; } else { + // Load any other assembly from the solution. + foreach(var project in ProjectService.OpenSolution.Projects) { + if(project.AssemblyName==name) { + var pc = ParserService.GetProjectContent(project); + if (pc != null) + return this.typeResolutionService.LoadAssembly(pc); + } + + } return base.LoadAssembly(name); } } diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.AddIn/Src/WpfDisplayBinding.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.AddIn/Src/WpfDisplayBinding.cs index 11148fcc19..7b2e51aca5 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.AddIn/Src/WpfDisplayBinding.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.AddIn/Src/WpfDisplayBinding.cs @@ -45,12 +45,12 @@ namespace ICSharpCode.WpfDesign.AddIn r.XmlResolver = null; r.WhitespaceHandling = WhitespaceHandling.None; while (r.NodeType != XmlNodeType.Element && r.Read()); - - if (r.LocalName == "Window" || r.LocalName == "UserControl") - return true; + if(r.LocalName=="ResourceDictionary") + return false; } catch (XmlException) { - return false; + return true; } + return true; } } return false; diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.AddIn/Src/WpfViewContent.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.AddIn/Src/WpfViewContent.cs index c17d8dcf85..51117ea37d 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.AddIn/Src/WpfViewContent.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.AddIn/Src/WpfViewContent.cs @@ -128,12 +128,15 @@ namespace ICSharpCode.WpfDesign.AddIn } } else{ - _stream.Position = 0; - using (var reader = new StreamReader(_stream)) + if(_stream.CanRead){ + _stream.Position = 0; + using (var reader = new StreamReader(_stream)) using (var writer = new StreamWriter(stream)) { - writer.Write(reader.ReadToEnd()); + writer.Write(reader.ReadToEnd()); + } } } + } void UpdateTasks(XamlErrorService xamlErrorService) diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/WindowResizeBehavior.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/RootItemBehavior.cs similarity index 60% rename from src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/WindowResizeBehavior.cs rename to src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/RootItemBehavior.cs index d6e6a7eb0a..8f7f39ae97 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/WindowResizeBehavior.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/RootItemBehavior.cs @@ -1,30 +1,32 @@ // // // -// -// $Revision$ +// +// $Revision: $ // - using System; -using System.Collections.Generic; using System.Windows; -using ICSharpCode.WpfDesign.Extensions; +using System.Collections.Generic; +using System.Diagnostics; -namespace ICSharpCode.WpfDesign.Designer.Extensions +namespace ICSharpCode.WpfDesign.Designer { /// - /// Supports resizing a Window. + /// Intializes different behaviors for the Root item. + /// Could not be a extension since Root Item is can be of any type /// - [ExtensionFor(typeof(Window))] - public class WindowResizeBehavior : BehaviorExtension, IRootPlacementBehavior + public class RootItemBehavior : IRootPlacementBehavior { - protected override void OnInitialized() + private DesignItem _rootItem; + + public void Intialize(DesignContext context) { - base.OnInitialized(); - this.ExtendedItem.AddBehavior(typeof(IRootPlacementBehavior), this); + Debug.Assert(context.RootItem!=null); + this._rootItem=context.RootItem; + _rootItem.AddBehavior(typeof(IRootPlacementBehavior),this); } - public bool CanPlace(ICollection children, PlacementType type, PlacementAlignment position) + public bool CanPlace(System.Collections.Generic.ICollection childItems, PlacementType type, PlacementAlignment position) { return type == PlacementType.Resize && (position == PlacementAlignment.Right @@ -32,23 +34,25 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions || position == PlacementAlignment.Bottom); } - public void BeginPlacement(PlacementOperation operation) { + } public void EndPlacement(PlacementOperation operation) { + } - public Rect GetPosition(PlacementOperation operation, DesignItem childItem) + public System.Windows.Rect GetPosition(PlacementOperation operation, DesignItem childItem) { UIElement child = childItem.View; return new Rect(0, 0, ModelTools.GetWidth(child), ModelTools.GetHeight(child)); } - - public void BeforeSetPosition(PlacementOperation operation) + + public void BeforeSetPosition(PlacementOperation operation) { + throw new NotImplementedException(); } public void SetPosition(PlacementInformation info) @@ -70,7 +74,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions public void LeaveContainer(PlacementOperation operation) { - throw new NotSupportedException(); + throw new NotImplementedException(); } public bool CanEnterContainer(PlacementOperation operation) @@ -80,7 +84,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions public void EnterContainer(PlacementOperation operation) { - throw new NotSupportedException(); + throw new NotImplementedException(); } } } diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/WpfDesign.Designer.csproj b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/WpfDesign.Designer.csproj index 223aba36cd..dcff7747f2 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/WpfDesign.Designer.csproj +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/WpfDesign.Designer.csproj @@ -139,7 +139,6 @@ - @@ -197,6 +196,7 @@ PropertyGridView.xaml + ChooseClassDialog.xaml diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlDesignContext.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlDesignContext.cs index 56a7e30649..3cdb4fc180 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlDesignContext.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlDesignContext.cs @@ -95,6 +95,12 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml _rootItem = _componentService.RegisterXamlComponentRecursive(_doc.RootElement); + if(_rootItem!=null){ + var rootBehavior=new RootItemBehavior(); + rootBehavior.Intialize(this); + } + + _xamlEditOperations=new XamlEditOperations(this,parserSettings); } diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlParser.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlParser.cs index d63fe41463..d851b96edd 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlParser.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlParser.cs @@ -228,6 +228,21 @@ namespace ICSharpCode.WpfDesign.XamlDom } foreach (XmlAttribute attribute in element.Attributes) { + if (attribute.Value.StartsWith("clr-namespace", StringComparison.OrdinalIgnoreCase)) { + // the format is "clr-namespace:;assembly=" + var clrNamespace = attribute.Value.Split(new[] {':', ';', '='}); + if (clrNamespace.Length == 4) { + // get the assembly name + var assembly=settings.TypeFinder.LoadAssembly(clrNamespace[3]); + if(assembly!=null) + settings.TypeFinder.RegisterAssembly(assembly); + } else { + // if no assembly name is there, then load the assembly of the opened file. + var assembly=settings.TypeFinder.LoadAssembly(null); + if(assembly!=null) + settings.TypeFinder.RegisterAssembly(assembly); + } + } if (attribute.NamespaceURI == XamlConstants.XmlnsNamespace) continue; if (attribute.Name == "xml:space") { @@ -586,27 +601,27 @@ namespace ICSharpCode.WpfDesign.XamlDom /// Parser settings used by . /// Returns the XamlObject of the parsed . public static XamlObject ParseSnippet(XamlObject root, string xaml, XamlParserSettings settings) - { - XmlTextReader reader = new XmlTextReader(new StringReader(xaml)); - var element = root.OwnerDocument.XmlDocument.ReadNode(reader); - - if (element != null) { - XmlAttribute xmlnsAttribute=null; - foreach (XmlAttribute attrib in element.Attributes) { - if (attrib.Name == "xmlns") - xmlnsAttribute = attrib; - } - if(xmlnsAttribute!=null) - element.Attributes.Remove(xmlnsAttribute); + { + XmlTextReader reader = new XmlTextReader(new StringReader(xaml)); + var element = root.OwnerDocument.XmlDocument.ReadNode(reader); + + if (element != null) { + XmlAttribute xmlnsAttribute=null; + foreach (XmlAttribute attrib in element.Attributes) { + if (attrib.Name == "xmlns") + xmlnsAttribute = attrib; + } + if(xmlnsAttribute!=null) + element.Attributes.Remove(xmlnsAttribute); - XamlParser parser = new XamlParser(); - parser.settings = settings; - parser.document = root.OwnerDocument; - var xamlObject = parser.ParseObject(element as XmlElement); - if (xamlObject != null) - return xamlObject; - } - return null; - } + XamlParser parser = new XamlParser(); + parser.settings = settings; + parser.document = root.OwnerDocument; + var xamlObject = parser.ParseObject(element as XmlElement); + if (xamlObject != null) + return xamlObject; + } + return null; + } } }