Browse Source

Add image loading and custom control support to WpfDesign.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@2577 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 18 years ago
parent
commit
43061cd1d8
  1. 3
      src/AddIns/DisplayBindings/WpfDesign/StandaloneDesigner/Window1.xaml.cs
  2. 39
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.AddIn/Src/FileUriContext.cs
  3. 62
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.AddIn/Src/MyTypeFinder.cs
  4. 13
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.AddIn/Src/PropertyDescriptionService.cs
  5. 14
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.AddIn/Src/WpfViewContent.cs
  6. 11
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.AddIn/WpfDesign.AddIn.csproj
  7. 5
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.AddIn/WpfDesign.addin
  8. 4
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignSurface.cs
  9. 1
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/WpfDesign.Designer.csproj
  10. 25
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlDesignContext.cs
  11. 38
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlLoadSettings.cs
  12. 3
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/Designer/ModelTestHelper.cs
  13. 53
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlDocument.cs
  14. 7
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlMarkupValue.cs
  15. 12
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlParser.cs
  16. 23
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlParserSettings.cs
  17. 16
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlTextValue.cs

3
src/AddIns/DisplayBindings/WpfDesign/StandaloneDesigner/Window1.xaml.cs

@ -41,7 +41,7 @@ namespace StandaloneDesigner @@ -41,7 +41,7 @@ namespace StandaloneDesigner
{
if (e.Source != tabControl) return;
if (tabControl.SelectedItem == designTab) {
designSurface.LoadDesigner(new XmlTextReader(new StringReader(CodeTextBox.Text)));
designSurface.LoadDesigner(new XmlTextReader(new StringReader(CodeTextBox.Text)), null);
designSurface.DesignContext.Services.Selection.SelectionChanged += OnSelectionChanged;
toolbox.ToolService = designSurface.DesignContext.Services.Tool;
} else {
@ -105,3 +105,4 @@ namespace StandaloneDesigner @@ -105,3 +105,4 @@ namespace StandaloneDesigner
}

39
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.AddIn/Src/FileUriContext.cs

@ -0,0 +1,39 @@ @@ -0,0 +1,39 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <author name="Daniel Grunwald"/>
// <version>$Revision$</version>
// </file>
using System;
using System.IO;
using System.Windows.Markup;
using ICSharpCode.SharpDevelop;
namespace ICSharpCode.WpfDesign.AddIn
{
/// <summary>
/// Used to support loading Image.ImageSource.
/// </summary>
public class FileUriContext : IUriContext
{
OpenedFile file;
public FileUriContext(OpenedFile file)
{
if (file == null)
throw new ArgumentNullException("file");
this.file = file;
}
public Uri BaseUri {
get {
return new Uri(file.FileName);
}
set {
throw new NotSupportedException();
}
}
}
}

62
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.AddIn/Src/MyTypeFinder.cs

@ -0,0 +1,62 @@ @@ -0,0 +1,62 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <author name="Daniel Grunwald"/>
// <version>$Revision$</version>
// </file>
using System;
using System.Reflection;
using ICSharpCode.WpfDesign.XamlDom;
using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.Dom;
using ICSharpCode.SharpDevelop.Project;
using TypeResolutionService = ICSharpCode.FormsDesigner.Services.TypeResolutionService;
namespace ICSharpCode.WpfDesign.AddIn
{
public class MyTypeFinder : XamlTypeFinder
{
OpenedFile file;
public static MyTypeFinder Create(OpenedFile file)
{
MyTypeFinder f = new MyTypeFinder();
f.file = file;
f.ImportFrom(CreateWpfTypeFinder());
return f;
}
public override Assembly LoadAssembly(string name)
{
if (string.IsNullOrEmpty(name)) {
IProjectContent pc = GetProjectContent(file);
if (pc != null) {
return TypeResolutionService.LoadAssembly(pc);
}
return null;
} else {
return base.LoadAssembly(name);
}
}
public override XamlTypeFinder Clone()
{
MyTypeFinder copy = new MyTypeFinder();
copy.file = this.file;
copy.ImportFrom(this);
return copy;
}
internal static IProjectContent GetProjectContent(OpenedFile file)
{
if (ProjectService.OpenSolution != null && file != null) {
IProject p = ProjectService.OpenSolution.FindProjectContainingFile(file.FileName);
if (p != null) {
return ParserService.GetProjectContent(p);
}
}
return ParserService.DefaultProjectContent;
}
}
}

13
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.AddIn/Src/PropertyDescriptionService.cs

@ -26,7 +26,7 @@ namespace ICSharpCode.WpfDesign.AddIn @@ -26,7 +26,7 @@ namespace ICSharpCode.WpfDesign.AddIn
public object GetDescription(DesignItemProperty property)
{
IProjectContent pc = GetProjectContent();
IProjectContent pc = MyTypeFinder.GetProjectContent(file);
if (pc != null) {
string fullName = property.DeclaringType.FullName + "." + property.Name;
IDecoration dec = pc.GetElement(fullName);
@ -40,16 +40,5 @@ namespace ICSharpCode.WpfDesign.AddIn @@ -40,16 +40,5 @@ namespace ICSharpCode.WpfDesign.AddIn
}
return null;
}
IProjectContent GetProjectContent()
{
if (ProjectService.OpenSolution != null) {
IProject p = ProjectService.OpenSolution.FindProjectContainingFile(file.FileName);
if (p != null) {
return ParserService.GetProjectContent(p);
}
}
return ParserService.DefaultProjectContent;
}
}
}

14
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.AddIn/Src/WpfViewContent.cs

@ -6,17 +6,19 @@ @@ -6,17 +6,19 @@
// </file>
using System;
using System.Diagnostics;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using System.Windows.Forms;
using System.Windows.Forms.Integration;
using System.Windows.Markup;
using System.Xml;
using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.Gui;
using ICSharpCode.WpfDesign.Designer;
using ICSharpCode.WpfDesign.Designer.Services;
using ICSharpCode.WpfDesign.Designer.Xaml;
using ICSharpCode.WpfDesign.PropertyEditor;
namespace ICSharpCode.WpfDesign.AddIn
@ -47,7 +49,15 @@ namespace ICSharpCode.WpfDesign.AddIn @@ -47,7 +49,15 @@ namespace ICSharpCode.WpfDesign.AddIn
InitPropertyEditor();
}
using (XmlTextReader r = new XmlTextReader(stream)) {
designer.LoadDesigner(r);
XamlLoadSettings settings = new XamlLoadSettings();
settings.CustomServiceRegisterFunctions.Add(
delegate(XamlDesignContext context) {
context.Services.AddService(typeof(IUriContext), new FileUriContext(this.PrimaryFile));
});
settings.TypeFinder = MyTypeFinder.Create(this.PrimaryFile);
designer.LoadDesigner(r, settings);
designer.DesignContext.Services.AddService(typeof(IPropertyDescriptionService), new PropertyDescriptionService(this.PrimaryFile));
designer.DesignContext.Services.Selection.SelectionChanged += OnSelectionChanged;
designer.DesignContext.Services.GetService<UndoService>().UndoStackChanged += OnUndoStackChanged;

11
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.AddIn/WpfDesign.AddIn.csproj

@ -52,6 +52,8 @@ @@ -52,6 +52,8 @@
<Link>Configuration\GlobalAssemblyInfo.cs</Link>
</Compile>
<Compile Include="Configuration\AssemblyInfo.cs" />
<Compile Include="Src\FileUriContext.cs" />
<Compile Include="Src\MyTypeFinder.cs" />
<Compile Include="Src\PropertyDescriptionService.cs" />
<Compile Include="Src\SharpDevelopElementHost.cs" />
<Compile Include="Src\WpfDisplayBinding.cs" />
@ -85,11 +87,20 @@ @@ -85,11 +87,20 @@
<Name>ICSharpCode.SharpDevelop.Widgets</Name>
<Private>False</Private>
</ProjectReference>
<ProjectReference Include="..\..\FormsDesigner\Project\FormsDesigner.csproj">
<Project>{7D7E92DF-ACEB-4B69-92C8-8AC7A703CD57}</Project>
<Name>FormsDesigner</Name>
</ProjectReference>
<ProjectReference Include="..\WpfDesign.Designer\Project\WpfDesign.Designer.csproj">
<Project>{78CC29AC-CC79-4355-B1F2-97936DF198AC}</Project>
<Name>WpfDesign.Designer</Name>
<Private>False</Private>
</ProjectReference>
<ProjectReference Include="..\WpfDesign.XamlDom\Project\WpfDesign.XamlDom.csproj">
<Project>{88DA149F-21B2-48AB-82C4-28FB6BDFD783}</Project>
<Name>WpfDesign.XamlDom</Name>
<Private>False</Private>
</ProjectReference>
<ProjectReference Include="..\WpfDesign\Project\WpfDesign.csproj">
<Project>{66A378A1-E9F4-4AD5-8946-D0EC06C2902F}</Project>
<Name>WpfDesign</Name>

5
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.AddIn/WpfDesign.addin

@ -3,6 +3,11 @@ @@ -3,6 +3,11 @@
copyright = "prj:///doc/copyright.txt"
description = "WPF Designer">
<Manifest>
<Identity name="ICSharpCode.WpfDesigner"/>
<Dependency addin = "ICSharpCode.FormsDesigner" requirePreload = "true"/>
</Manifest>
<Runtime>
<Import assembly = "ICSharpCode.WpfDesign.AddIn.dll"/>
</Runtime>

4
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignSurface.cs

@ -125,10 +125,10 @@ namespace ICSharpCode.WpfDesign.Designer @@ -125,10 +125,10 @@ namespace ICSharpCode.WpfDesign.Designer
/// <summary>
/// Initializes the designer content from the specified XmlReader.
/// </summary>
public void LoadDesigner(XmlReader xamlReader)
public void LoadDesigner(XmlReader xamlReader, Xaml.XamlLoadSettings loadSettings)
{
UnloadDesigner();
InitializeDesigner(new Xaml.XamlDesignContext(xamlReader));
InitializeDesigner(new Xaml.XamlDesignContext(xamlReader, loadSettings ?? new Xaml.XamlLoadSettings()));
}
/// <summary>

1
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/WpfDesign.Designer.csproj

@ -101,6 +101,7 @@ @@ -101,6 +101,7 @@
<Compile Include="Services\ViewService.cs" />
<Compile Include="DesignSurface.cs" />
<Compile Include="SharedInstances.cs" />
<Compile Include="Xaml\XamlLoadSettings.cs" />
<Compile Include="Xaml\XamlModelCollectionElementsCollection.cs" />
<Compile Include="Xaml\XamlComponentService.cs" />
<Compile Include="Xaml\XamlDesignContext.cs" />

25
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlDesignContext.cs

@ -7,6 +7,7 @@ @@ -7,6 +7,7 @@
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Xml;
using ICSharpCode.WpfDesign.XamlDom;
using ICSharpCode.WpfDesign.Designer.Services;
@ -32,10 +33,12 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml @@ -32,10 +33,12 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml
/// <summary>
/// Creates a new XamlDesignContext instance.
/// </summary>
public XamlDesignContext(XmlReader xamlReader)
public XamlDesignContext(XmlReader xamlReader, XamlLoadSettings loadSettings)
{
if (xamlReader == null)
throw new ArgumentNullException("xamlReader");
if (loadSettings == null)
throw new ArgumentNullException("loadSettings");
this.Services.AddService(typeof(ISelectionService), new DefaultSelectionService());
this.Services.AddService(typeof(IToolService), new DefaultToolService(this));
@ -50,13 +53,21 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml @@ -50,13 +53,21 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml
EditorManager propertyGridEditorManager = new EditorManager();
this.Services.AddService(typeof(EditorManager), propertyGridEditorManager);
// register extensions from this assembly:
this.Services.ExtensionManager.RegisterAssembly(typeof(XamlDesignContext).Assembly);
propertyGridEditorManager.RegisterAssembly(typeof(XamlDesignContext).Assembly);
foreach (Action<XamlDesignContext> action in loadSettings.CustomServiceRegisterFunctions) {
action(this);
}
XamlParserSettings xamlParseSettings = new XamlParserSettings();
xamlParseSettings.CreateInstanceCallback = this.Services.ExtensionManager.CreateInstanceWithCustomInstanceFactory;
_doc = XamlParser.Parse(xamlReader, xamlParseSettings);
// register extensions from the designer assemblies:
foreach (Assembly designerAssembly in loadSettings.DesignerAssemblies) {
this.Services.ExtensionManager.RegisterAssembly(designerAssembly);
propertyGridEditorManager.RegisterAssembly(designerAssembly);
}
XamlParserSettings parserSettings = new XamlParserSettings();
parserSettings.TypeFinder = loadSettings.TypeFinder;
parserSettings.CreateInstanceCallback = this.Services.ExtensionManager.CreateInstanceWithCustomInstanceFactory;
parserSettings.ServiceProvider = this.Services;
_doc = XamlParser.Parse(xamlReader, parserSettings);
_rootItem = _componentService.RegisterXamlComponentRecursive(_doc.RootElement);
}

38
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlLoadSettings.cs

@ -0,0 +1,38 @@ @@ -0,0 +1,38 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <author name="Daniel Grunwald"/>
// <version>$Revision$</version>
// </file>
using System;
using System.Collections.Generic;
using System.Reflection;
using ICSharpCode.WpfDesign.XamlDom;
namespace ICSharpCode.WpfDesign.Designer.Xaml
{
/// <summary>
/// Settings used to load a XAML document.
/// </summary>
public sealed class XamlLoadSettings
{
public readonly ICollection<Assembly> DesignerAssemblies = new List<Assembly>();
public readonly List<Action<XamlDesignContext>> CustomServiceRegisterFunctions = new List<Action<XamlDesignContext>>();
XamlTypeFinder typeFinder = XamlTypeFinder.CreateWpfTypeFinder();
public XamlTypeFinder TypeFinder {
get { return typeFinder; }
set {
if (value == null)
throw new ArgumentNullException("value");
typeFinder = value;
}
}
public XamlLoadSettings()
{
DesignerAssemblies.Add(typeof(XamlDesignContext).Assembly);
}
}
}

3
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/Designer/ModelTestHelper.cs

@ -30,7 +30,7 @@ namespace ICSharpCode.WpfDesign.Tests.Designer @@ -30,7 +30,7 @@ namespace ICSharpCode.WpfDesign.Tests.Designer
protected XamlDesignContext CreateContext(string xaml)
{
log = new StringBuilder();
XamlDesignContext context = new XamlDesignContext(new XmlTextReader(new StringReader(xaml)));
XamlDesignContext context = new XamlDesignContext(new XmlTextReader(new StringReader(xaml)), null);
/*context.Services.Component.ComponentRegistered += delegate(object sender, DesignItemEventArgs e) {
log.AppendLine("Register " + ItemIdentity(e.Item));
};
@ -96,3 +96,4 @@ namespace ICSharpCode.WpfDesign.Tests.Designer @@ -96,3 +96,4 @@ namespace ICSharpCode.WpfDesign.Tests.Designer
}
}
}

53
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlDocument.cs

@ -18,6 +18,7 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -18,6 +18,7 @@ namespace ICSharpCode.WpfDesign.XamlDom
{
XmlDocument _xmlDoc;
XamlObject _rootElement;
IServiceProvider _serviceProvider;
XamlTypeFinder _typeFinder;
@ -29,7 +30,48 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -29,7 +30,48 @@ namespace ICSharpCode.WpfDesign.XamlDom
/// Gets the service provider used for markup extensions in this document.
/// </summary>
public IServiceProvider ServiceProvider {
get { return null; }
get { return _serviceProvider; }
}
internal ITypeDescriptorContext GetTypeDescriptorContext()
{
return new DummyTypeDescriptorContext(this);
}
sealed class DummyTypeDescriptorContext : ITypeDescriptorContext
{
XamlDocument document;
public DummyTypeDescriptorContext(XamlDocument document)
{
this.document = document;
}
public IContainer Container {
get { return null; }
}
public object Instance {
get { return null; }
}
public PropertyDescriptor PropertyDescriptor {
get { return null; }
}
public bool OnComponentChanging()
{
return false;
}
public void OnComponentChanged()
{
}
public object GetService(Type serviceType)
{
return document.ServiceProvider.GetService(serviceType);
}
}
/// <summary>
@ -59,10 +101,11 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -59,10 +101,11 @@ namespace ICSharpCode.WpfDesign.XamlDom
/// <summary>
/// Internal constructor, used by XamlParser.
/// </summary>
internal XamlDocument(XmlDocument xmlDoc, XamlTypeFinder typeFinder)
internal XamlDocument(XmlDocument xmlDoc, XamlParserSettings settings)
{
this._xmlDoc = xmlDoc;
this._typeFinder = typeFinder;
this._typeFinder = settings.TypeFinder;
this._serviceProvider = settings.ServiceProvider;
}
/// <summary>
@ -86,7 +129,7 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -86,7 +129,7 @@ namespace ICSharpCode.WpfDesign.XamlDom
/// </summary>
public XamlPropertyValue CreateNullValue()
{
return new XamlMarkupValue(this, (XamlObject)CreatePropertyValue(new System.Windows.Markup.NullExtension(), null));
return new XamlMarkupValue((XamlObject)CreatePropertyValue(new System.Windows.Markup.NullExtension(), null));
}
/// <summary>
@ -102,7 +145,7 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -102,7 +145,7 @@ namespace ICSharpCode.WpfDesign.XamlDom
bool hasStringConverter = c.CanConvertTo(typeof(string)) && c.CanConvertFrom(typeof(string));
if (forProperty != null && hasStringConverter) {
return new XamlTextValue(c.ConvertToInvariantString(instance));
return new XamlTextValue(this, c.ConvertToInvariantString(instance));
}

7
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlMarkupValue.cs

@ -6,6 +6,7 @@ @@ -6,6 +6,7 @@
// </file>
using System;
using System.ComponentModel;
using System.Windows.Markup;
namespace ICSharpCode.WpfDesign.XamlDom
@ -15,18 +16,16 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -15,18 +16,16 @@ namespace ICSharpCode.WpfDesign.XamlDom
/// </summary>
public class XamlMarkupValue : XamlPropertyValue
{
readonly XamlDocument doc;
XamlObject markupObject;
internal XamlMarkupValue(XamlDocument doc, XamlObject markupObject)
internal XamlMarkupValue(XamlObject markupObject)
{
this.doc = doc;
this.markupObject = markupObject;
}
internal override object GetValueFor(XamlPropertyInfo targetProperty)
{
return ((MarkupExtension)markupObject.Instance).ProvideValue(doc.ServiceProvider);
return ((MarkupExtension)markupObject.Instance).ProvideValue(markupObject.OwnerDocument.ServiceProvider);
}
internal override void OnParentPropertyChanged()

12
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlParser.cs

@ -94,7 +94,7 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -94,7 +94,7 @@ namespace ICSharpCode.WpfDesign.XamlDom
throw new ArgumentNullException("document");
XamlParser p = new XamlParser();
p.settings = settings;
p.document = new XamlDocument(document, settings.TypeFinder);
p.document = new XamlDocument(document, settings);
p.document.ParseComplete(p.ParseObject(document.DocumentElement));
return p.document;
}
@ -118,7 +118,7 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -118,7 +118,7 @@ namespace ICSharpCode.WpfDesign.XamlDom
if (attribute.NamespaceURI.Length > 0)
return attribute.NamespaceURI;
else
return attribute.OwnerElement.NamespaceURI;
return attribute.OwnerElement.GetNamespaceOfPrefix("");
}
readonly static object[] emptyObjectArray = new object[0];
@ -158,7 +158,7 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -158,7 +158,7 @@ namespace ICSharpCode.WpfDesign.XamlDom
object instance;
if (initializeFromTextValueInsteadOfConstructor != null) {
instance = TypeDescriptor.GetConverter(elementType).ConvertFromInvariantString(initializeFromTextValueInsteadOfConstructor.Text);
instance = TypeDescriptor.GetConverter(elementType).ConvertFromString(initializeFromTextValueInsteadOfConstructor.Text);
} else {
instance = settings.CreateInstanceCallback(elementType, emptyObjectArray);
}
@ -294,11 +294,11 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -294,11 +294,11 @@ namespace ICSharpCode.WpfDesign.XamlDom
{
XmlText childText = childNode as XmlText;
if (childText != null) {
return new XamlTextValue(childText, currentXmlSpace);
return new XamlTextValue(document, childText, currentXmlSpace);
}
XmlCDataSection cData = childNode as XmlCDataSection;
if (cData != null) {
return new XamlTextValue(cData, currentXmlSpace);
return new XamlTextValue(document, cData, currentXmlSpace);
}
XmlElement element = childNode as XmlElement;
if (element != null) {
@ -401,7 +401,7 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -401,7 +401,7 @@ namespace ICSharpCode.WpfDesign.XamlDom
void ParseObjectAttribute(XamlObject obj, XmlAttribute attribute)
{
XamlPropertyInfo propertyInfo = GetPropertyInfo(obj.Instance, obj.ElementType, attribute);
XamlTextValue textValue = new XamlTextValue(attribute);
XamlTextValue textValue = new XamlTextValue(document, attribute);
propertyInfo.SetValue(obj.Instance, textValue.GetValueFor(propertyInfo));
obj.AddProperty(new XamlProperty(obj, propertyInfo, textValue));
}

23
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlParserSettings.cs

@ -21,6 +21,7 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -21,6 +21,7 @@ namespace ICSharpCode.WpfDesign.XamlDom
{
CreateInstanceCallback _createInstanceCallback = Activator.CreateInstance;
XamlTypeFinder _typeFinder = XamlTypeFinder.CreateWpfTypeFinder();
IServiceProvider _serviceProvider = DummyServiceProvider.Instance;
/// <summary>
/// Gets/Sets the method used to create object instances.
@ -45,5 +46,27 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -45,5 +46,27 @@ namespace ICSharpCode.WpfDesign.XamlDom
_typeFinder = value;
}
}
/// <summary>
/// Gets/Sets the service provider to use to initialize markup extensions.
/// </summary>
public IServiceProvider ServiceProvider {
get { return _serviceProvider; }
set {
if (value == null)
throw new ArgumentNullException("value");
_serviceProvider = value;
}
}
sealed class DummyServiceProvider : IServiceProvider
{
public static readonly DummyServiceProvider Instance = new DummyServiceProvider();
public object GetService(Type serviceType)
{
return null;
}
}
}
}

16
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlTextValue.cs

@ -9,6 +9,7 @@ using System; @@ -9,6 +9,7 @@ using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;
using System.Text;
using System.Xml;
@ -19,30 +20,35 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -19,30 +20,35 @@ namespace ICSharpCode.WpfDesign.XamlDom
/// </summary>
public sealed class XamlTextValue : XamlPropertyValue
{
XamlDocument document;
XmlAttribute attribute;
XmlText textNode;
XmlSpace xmlSpace;
string textValue;
XmlCDataSection cDataSection;
internal XamlTextValue(XmlAttribute attribute)
internal XamlTextValue(XamlDocument document, XmlAttribute attribute)
{
this.document = document;
this.attribute = attribute;
}
internal XamlTextValue(string textValue)
internal XamlTextValue(XamlDocument document, string textValue)
{
this.document = document;
this.textValue = textValue;
}
internal XamlTextValue(XmlText textNode, XmlSpace xmlSpace)
internal XamlTextValue(XamlDocument document, XmlText textNode, XmlSpace xmlSpace)
{
this.document = document;
this.xmlSpace = xmlSpace;
this.textNode = textNode;
}
internal XamlTextValue(XmlCDataSection cDataSection, XmlSpace xmlSpace)
internal XamlTextValue(XamlDocument document, XmlCDataSection cDataSection, XmlSpace xmlSpace)
{
this.document = document;
this.xmlSpace = xmlSpace;
this.cDataSection = cDataSection;
}
@ -105,7 +111,7 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -105,7 +111,7 @@ namespace ICSharpCode.WpfDesign.XamlDom
return this.Text;
TypeConverter converter = targetProperty.TypeConverter;
if (converter != null) {
return converter.ConvertFromInvariantString(this.Text);
return converter.ConvertFromString(document.GetTypeDescriptorContext(), CultureInfo.InvariantCulture, this.Text);
} else {
return this.Text;
}

Loading…
Cancel
Save