简体   繁体   中英

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:

<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}]

Is it possible to do this directly, or do I have to "create a view" (eg. extract to an object, run an xslt, etc)

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. Or if you dont want to convert xml into clr objects use XPath property when Binding. Thought you will have to specify where is your xml data located.

Check this link out:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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