Skip to content

Commit 680743f

Browse files
committed
better copy & paste
1 parent cbd8f6c commit 680743f

2 files changed

Lines changed: 15 additions & 6 deletions

File tree

WpfDesign.XamlDom/Project/XamlFormatter.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,10 @@ static void WalkElement(XElement e, Dictionary<XamlElementLineInfo, XamlElementL
6363

6464
Console.WriteLine(info.LinePosition);
6565
NewLine();
66-
string prefix1 = e.GetPrefixOfNamespace(e.Name.Namespace);
66+
var defaultNs = e.GetDefaultNamespace();
67+
string prefix1 = null;
68+
if (defaultNs != e.Name.Namespace)
69+
prefix1 = e.GetPrefixOfNamespace(e.Name.Namespace);
6770
string name1 = prefix1 == null ? e.Name.LocalName : prefix1 + ":" + e.Name.LocalName;
6871
newLineInfo.Position = sb.Length;
6972
Append("<" + name1);
@@ -72,7 +75,9 @@ static void WalkElement(XElement e, Dictionary<XamlElementLineInfo, XamlElementL
7275
int length = name1.Length;
7376

7477
foreach (var a in e.Attributes()) {
75-
string prefix2 = e.GetPrefixOfNamespace(a.Name.Namespace);
78+
string prefix2 = null;
79+
if (defaultNs != a.Name.Namespace)
80+
prefix2 = e.GetPrefixOfNamespace(a.Name.Namespace);
7681
var g = new AttributeString() { Name = a.Name, Prefix = prefix2, Value = a.Value };
7782
list.Add(g);
7883
length += g.FinalString.Length;

WpfDesign.XamlDom/Project/XamlStaticTools.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,14 @@ public static string GetXaml(XamlObject xamlObject)
4949
{
5050
if (attribute.Name.StartsWith("xmlns:"))
5151
{
52-
if (!attLst.ContainsKey(attribute.Name))
53-
{
54-
nd.Attributes.Append((XmlAttribute)attribute.CloneNode(false));
55-
attLst.Add(attribute.Name, attribute);
52+
var existingNs = nd.GetNamespaceOfPrefix(attribute.Name.Substring(6));
53+
if (string.IsNullOrEmpty(existingNs))
54+
{
55+
if (!attLst.ContainsKey(attribute.Name))
56+
{
57+
nd.Attributes.Append((XmlAttribute)attribute.CloneNode(false));
58+
attLst.Add(attribute.Name, attribute);
59+
}
5660
}
5761
}
5862
}

0 commit comments

Comments
 (0)