简体   繁体   English

如何将WPF与XML绑定用于具有从兄弟姐妹到父级的相关数据的指定路径

[英]How do I use WPF binding with XML for a specified path with related data from siblings to the parent

I have an xml document structured like so: 我有一个这样的xml文档:

<db>
    <table1>
        <row>
            <id>1</id>
            <val1>1</val1>
            <val2>1</val2>
        </row>
        <row>
            <id>2</id>
            <val1>2</val1>
            <val2>2</val2>
        </row>
    </table1>
    <table2>
        <row>
            <id>1</id>
            <name>a</name>
        </row>
        <row>
            <id>2</id>
            <name>b</name>
        </row>
    </table2>
    <table3>
        <row>
            <id>1</id>
            <name>x</name>
        </row>
        <row>
            <id>2</id>
            <name>y</name>
        </row>
    </table3>
</db>

I need to bind my object to /db/table1/row[id=1] and allow child objects to obtain //db/table{2/3}/row[id={boundrow}/val{1/2}] 我需要将我的对象绑定到/db/table1/row[id=1]并允许子对象获取//db/table{2/3}/row[id={boundrow}/val{1/2}]

Is it possible to do this directly, or do I have to "create a view" (eg. extract to an object, run an xslt, etc) 是否可以直接执行此操作,还是我必须“创建视图”(例如,提取到对象,运行xslt等)

I have a feeling you are about to create data structure with bindings. 我有一种感觉,您即将使用绑定创建数据结构。

Bindings transmit a value from target to source but they dont create complete data structure. 绑定将值从目标传输到源,但它们不会创建完整的数据结构。 Therefore first load your tree alike data from xml into clr objects and then bind your TextBoxes to them. 因此,首先将树的数据从xml加载到clr对象中,然后将TextBoxes绑定到它们。 Or if you dont want to convert xml into clr objects use XPath property when Binding. 或者,如果您不想将xml转换为clr对象,请在绑定时使用XPath属性。 Thought you will have to specify where is your xml data located. 以为您将必须指定XML数据位于何处。

Check this link out: 检查此链接:

http://msdn.microsoft.com/en-us/library/system.windows.data.binding.xpath.aspx http://msdn.microsoft.com/zh-CN/library/system.windows.data.binding.xpath.aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM