English 中文(简体)
Xaml Servicess。 储蓄基金正在产生一种X:Name=“_ReferenceID0”特性,而当时有RuntimeNameProperty。
原标题:XamlServices.Save is generating an x:Name="__ReferenceID0" attribute while there is the RuntimeNameProperty

I m having troubles with XamlServices Serialization/Deserialisation. I have this class :

[RuntimeNameProperty("Name")]
[ContentProperty("Children")]
public class Node
{
    public Node()
    {

    }

    public string   Name    { get; set; }
    public int      Valeur  { get; set; }

    public Node Parent
    {
        get;
        set;
    }

    public bool HasChildren
    {
        get { return mChildren.Count > 0; }
    }

    public NodeList Children
    {
        get { return mChildren; }
        set { mChildren = value; }
    }

    NodeList mChildren = new NodeList();
}

语言学家是一个短类,其定义是:

public class NodeList : IList<Node>
{
    // ... implemented using a List<Node> internally
}

If I create a node hierarchy, like this :

Node root = new Node() { Name = "A", Valeur = 2, Parent = null };
root.Children.Add( new Node() { Name = "A1", Valeur = 3, Parent = root } );
root.Children.Add( new Node() { Name = "A2", Valeur = 3, Parent = root } );
root.Children[0].Children.Add( new Node() { Name = "A21", Valeur = 5, Parent = root.Children[0] } );

并且我以这种方式编篡:

using( TextWriter writer = File.CreateText( "test.xaml" ) )
{
    XamlServices.Save( writer, root );
}

由此而产生的xaml :

<Node Parent="{x:Null}" x:Name="__ReferenceID1" Name="A" Valeur="2"
   xmlns="clr-namespace:TestCRTP;assembly=TestCRTP"
   xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <Node Parent="{x:Reference A}" x:Name="__ReferenceID0" Name="A1" Valeur="3">
        <Node Parent="{x:Reference A1}" Name="A21" Valeur="5">
            <NodeList />
        </Node>
    </Node>
    <Node Parent="{x:Reference A}" Name="A2" Valeur="3">
        <NodeList />
    </Node>
</Node>

如你所知,Xaml Services公司正在产生“_ReferenceID0”特性,因为有RuntimeNameProperty称号。 显然,它之所以这样做,是因为X:Reference(由于父母关系),但最棘手的是,它甚至不使用产生的x:Name! 当然,当我试图将其erial弄时,它就变得最糟:

using( TextReader reader = File.OpenText( "test.xaml" ) )
{
    Node node = XamlServices.Load( reader ) as Node;
}

我提到“姓名财产已经定在诺德”,这是合乎逻辑的,因为确实已经有一个名字......。

任何cl?

问题回答

There are only two solutions, either you have to change Name property to something else like XName or anything that is not "Name".

或者你必须放弃父母的序列化,

[DesignerSerializability(DesignerSerializability.Hidden)]
public Node Parent
{
    get;
    set;
}

但在这种情况下,在标书装满后,你必须处理你的节点,并人工确定父母。

理由XAML确实是将相互连接的物体图表编成序号,而不是仅仅一个树。 它使用名称来独一无二地识别节点,然而,正是这些节点的内部逻辑,现在允许你在试图解决参考名称时使用财产名称。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签