Skip to content
This repository was archived by the owner on Oct 16, 2020. It is now read-only.

Commit 241d8df

Browse files
Merge pull request #494 from gumme/WpfDesignerEnumFix
Added support for using enums.
2 parents 627081e + ba913a1 commit 241d8df

2 files changed

Lines changed: 25 additions & 3 deletions

File tree

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

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -668,6 +668,11 @@ public void AddBrushAsResource()
668668
}
669669

670670
public void AddNativeTypeAsResource(object component, string expectedXamlValue)
671+
{
672+
AddTypeAsResource(component, expectedXamlValue, "Controls0:", new string[] { "xmlns:Controls0=\"clr-namespace:System;assembly=mscorlib\""} );
673+
}
674+
675+
public void AddTypeAsResource(object component, string expectedXamlValue, string typePrefix, String[] additionalXmlns)
671676
{
672677
DesignItem textBlock = CreateCanvasContext("<TextBlock/>");
673678
DesignItem canvas = textBlock.Parent;
@@ -687,11 +692,11 @@ public void AddNativeTypeAsResource(object component, string expectedXamlValue)
687692
string typeName = component.GetType().Name;
688693

689694
string expectedXaml = "<Canvas.Resources>\n" +
690-
" <Controls0:" + typeName + " x:Key=\"res1\">" + expectedXamlValue + "</Controls0:" + typeName + ">\n" +
695+
" <" + typePrefix + typeName + " x:Key=\"res1\">" + expectedXamlValue + "</" + typePrefix + typeName + ">\n" +
691696
"</Canvas.Resources>\n" +
692697
"<TextBlock Tag=\"{StaticResource ResourceKey=res1}\" />";
693698

694-
AssertCanvasDesignerOutput(expectedXaml, textBlock.Context, "xmlns:Controls0=\"clr-namespace:System;assembly=mscorlib\"");
699+
AssertCanvasDesignerOutput(expectedXaml, textBlock.Context, additionalXmlns);
695700
AssertLog("");
696701
}
697702

@@ -736,6 +741,18 @@ public void AddInt32AsResource()
736741
const int i = 123;
737742
AddNativeTypeAsResource(i, "123");
738743
}
744+
745+
[Test]
746+
public void AddWpfEnumAsResource()
747+
{
748+
AddTypeAsResource(VerticalAlignment.Center, "Center", "", new string[0]);
749+
}
750+
751+
[Test]
752+
public void AddCustomEnumAsResource()
753+
{
754+
AddTypeAsResource(MyEnum.One, "One", "t:", new string[0]);
755+
}
739756
}
740757

741758
public class MyMultiConverter : IMultiValueConverter
@@ -760,4 +777,9 @@ public string StringProp {
760777
set { stringProp = value; }
761778
}
762779
}
780+
781+
public enum MyEnum
782+
{
783+
One, Two
784+
}
763785
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ internal string GetPrefixForNamespace(string @namespace)
275275

276276
bool IsNativeType(object instance)
277277
{
278-
return instance.GetType().Assembly == typeof(String).Assembly;
278+
return instance.GetType().Assembly == typeof(String).Assembly || instance.GetType().IsEnum;
279279
}
280280
}
281281
}

0 commit comments

Comments
 (0)