Browse Source

Merge pull request #494 from gumme/WpfDesignerEnumFix

Added support for using enums.
pull/725/head
Siegfried Pammer 11 years ago
parent
commit
241d8dfa97
  1. 26
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/Designer/ModelTests.cs
  2. 2
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlDocument.cs

26
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/Designer/ModelTests.cs

@ -668,6 +668,11 @@ namespace ICSharpCode.WpfDesign.Tests.Designer
} }
public void AddNativeTypeAsResource(object component, string expectedXamlValue) public void AddNativeTypeAsResource(object component, string expectedXamlValue)
{
AddTypeAsResource(component, expectedXamlValue, "Controls0:", new string[] { "xmlns:Controls0=\"clr-namespace:System;assembly=mscorlib\""} );
}
public void AddTypeAsResource(object component, string expectedXamlValue, string typePrefix, String[] additionalXmlns)
{ {
DesignItem textBlock = CreateCanvasContext("<TextBlock/>"); DesignItem textBlock = CreateCanvasContext("<TextBlock/>");
DesignItem canvas = textBlock.Parent; DesignItem canvas = textBlock.Parent;
@ -687,11 +692,11 @@ namespace ICSharpCode.WpfDesign.Tests.Designer
string typeName = component.GetType().Name; string typeName = component.GetType().Name;
string expectedXaml = "<Canvas.Resources>\n" + string expectedXaml = "<Canvas.Resources>\n" +
" <Controls0:" + typeName + " x:Key=\"res1\">" + expectedXamlValue + "</Controls0:" + typeName + ">\n" + " <" + typePrefix + typeName + " x:Key=\"res1\">" + expectedXamlValue + "</" + typePrefix + typeName + ">\n" +
"</Canvas.Resources>\n" + "</Canvas.Resources>\n" +
"<TextBlock Tag=\"{StaticResource ResourceKey=res1}\" />"; "<TextBlock Tag=\"{StaticResource ResourceKey=res1}\" />";
AssertCanvasDesignerOutput(expectedXaml, textBlock.Context, "xmlns:Controls0=\"clr-namespace:System;assembly=mscorlib\""); AssertCanvasDesignerOutput(expectedXaml, textBlock.Context, additionalXmlns);
AssertLog(""); AssertLog("");
} }
@ -736,6 +741,18 @@ namespace ICSharpCode.WpfDesign.Tests.Designer
const int i = 123; const int i = 123;
AddNativeTypeAsResource(i, "123"); AddNativeTypeAsResource(i, "123");
} }
[Test]
public void AddWpfEnumAsResource()
{
AddTypeAsResource(VerticalAlignment.Center, "Center", "", new string[0]);
}
[Test]
public void AddCustomEnumAsResource()
{
AddTypeAsResource(MyEnum.One, "One", "t:", new string[0]);
}
} }
public class MyMultiConverter : IMultiValueConverter public class MyMultiConverter : IMultiValueConverter
@ -760,4 +777,9 @@ namespace ICSharpCode.WpfDesign.Tests.Designer
set { stringProp = value; } set { stringProp = value; }
} }
} }
public enum MyEnum
{
One, Two
}
} }

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

@ -275,7 +275,7 @@ namespace ICSharpCode.WpfDesign.XamlDom
bool IsNativeType(object instance) bool IsNativeType(object instance)
{ {
return instance.GetType().Assembly == typeof(String).Assembly; return instance.GetType().Assembly == typeof(String).Assembly || instance.GetType().IsEnum;
} }
} }
} }

Loading…
Cancel
Save