diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/Designer/ModelTests.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/Designer/ModelTests.cs
index 44d4611df9..b3867622d5 100644
--- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/Designer/ModelTests.cs
+++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/Designer/ModelTests.cs
@@ -668,31 +668,52 @@ namespace ICSharpCode.WpfDesign.Tests.Designer
}
[Test]
- public void AddStringAsResource()
+ public void AddNativeTypeAsResource(object component, string expectedXamlValue)
{
DesignItem textBlock = CreateCanvasContext("");
DesignItem canvas = textBlock.Parent;
DesignItemProperty canvasResources = canvas.Properties.GetProperty("Resources");
- DesignItem str = canvas.Services.Component.RegisterComponentForDesigner("stringresource 1");
- str.Key = "str1";
+ DesignItem componentItem = canvas.Services.Component.RegisterComponentForDesigner(component);
+ componentItem.Key = "res1";
Assert.IsTrue(canvasResources.IsCollection);
- canvasResources.CollectionElements.Add(str);
+ canvasResources.CollectionElements.Add(componentItem);
+
+ DesignItemProperty prop = textBlock.Properties[TextBlock.TagProperty];
+ prop.SetValue(new StaticResourceExtension());
+ prop.Value.Properties["ResourceKey"].SetValue("res1");
- textBlock.Properties[TextBlock.TextProperty].SetValue(new StaticResourceExtension());
- DesignItemProperty prop = textBlock.Properties[TextBlock.TextProperty];
- prop.Value.Properties["ResourceKey"].SetValue("str1");
+ string typeName = component.GetType().Name;
string expectedXaml = "\n" +
- " stringresource 1\n" +
+ " " + expectedXamlValue + "\n" +
"\n" +
- "";
+ "";
AssertCanvasDesignerOutput(expectedXaml, textBlock.Context, "xmlns:Controls0=\"clr-namespace:System;assembly=mscorlib\"");
AssertLog("");
}
+
+ [Test]
+ public void AddStringAsResource()
+ {
+ AddNativeTypeAsResource("stringresource 1", "stringresource 1");
+ }
+
+ [Test]
+ public void AddDoubleAsResource()
+ {
+ AddNativeTypeAsResource(0.0123456789d, "0.0123456789");
+ }
+
+ [Test]
+ public void AddInt32AsResource()
+ {
+ const int i = 123;
+ AddNativeTypeAsResource(i, "123");
+ }
}
public class MyMultiConverter : IMultiValueConverter
diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlDocument.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlDocument.cs
index 3d79dea7e9..b324fd1bc7 100644
--- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlDocument.cs
+++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlDocument.cs
@@ -198,7 +198,7 @@ namespace ICSharpCode.WpfDesign.XamlDom
XmlElement xml = _xmlDoc.CreateElement(prefix, elementType.Name, ns);
- if (hasStringConverter && XamlObject.GetContentPropertyName(elementType) != null) {
+ if (hasStringConverter && (XamlObject.GetContentPropertyName(elementType) != null || IsNativeType(instance))) {
xml.InnerText = c.ConvertToInvariantString(instance);
} else if (instance is Brush && forProperty != null) { // TODO: this is a hacky fix, because Brush Editor doesn't
// edit Design Items and so we have no XML, only the Brush
@@ -219,8 +219,6 @@ namespace ICSharpCode.WpfDesign.XamlDom
}
}
}
- } else if (instance is string) {
- xml.InnerText = (string)instance;
}
return new XamlObject(this, xml, elementType, instance);
@@ -279,5 +277,10 @@ namespace ICSharpCode.WpfDesign.XamlDom
return prefix;
}
+
+ bool IsNativeType(object instance)
+ {
+ return instance.GetType().Assembly == typeof(String).Assembly;
+ }
}
}