c# - XPath 绑定(bind)以读取 wpf 中的 InnerXml

标签 c# xml wpf xpath binding

有没有办法在 wpf 中使用 XPath 绑定(bind)读取整个 InnerXml(或 OuterXml)?

示例数据提供者

<XmlDataProvider x:Key="SampleDataProvider" IsInitialLoadEnabled="True" IsAsynchronous="False" XPath="SampleDataProvider">
    <x:XData>
        <SampleData xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="">
            <Property ID="BlinkData">
                <Blink>
                    <Property ID="Name">Blink1</Property>
                    <Property ID="Speed">400</Property>
                    <Property ID="Value1">0</Property>
                    <Property ID="Value2">100</Property>
                </Blink>
            </Property>
        </SampleData>
    </x:XData>
</XmlDataProvider>

示例窗口

<TextBox>
    <TextBox.Text>
        <Binding Source="{StaticResource ResourceKey=SampleDataProvider}" XPath="/SampleData/Property[@ID='BlinkData']" />
    </TextBox.Text>
</TextBox>

我希望在文本框中看到整个 InnerXml。但不幸的是,我只看到节点值,例如 Blink14000100。

我是不是漏掉了什么?

最佳答案

好的!我想我找到了答案。 wpf 中的 XPath 最初会在内部返回一个 XmlNode,这可以通过向绑定(bind)语句 Path 添加另一个属性来拦截。

例如,

<TextBox Width="100" Height="100">
    <TextBox.Text>
        <Binding Source="{StaticResource ResourceKey=SampleDataProvider}" XPath="/SampleData/Property[@ID='BlinkData']" Path="InnerXml" />
    </TextBox.Text>
</TextBox >

注意 Path 属性在 Binding 语句中设置为 InnerXml!另外为此添加一个转换器并做任何你想做的事!

在此处找到此信息,http://msdn.microsoft.com/en-us/library/system.windows.data.binding.xpath.aspx

关于c# - XPath 绑定(bind)以读取 wpf 中的 InnerXml,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19110904/

相关文章:

c# - 如何将变量定义为类型列表<<>f_AnonymousType1<string,string>>

Python 文本文件到 xml

java - 使用 HBase 配置 Kundera

c++ - 用于 boost 序列化的与顺序无关的输入存档

wpf - 在WPF中的页面上添加网格背景图像

c# - 为什么禁用按钮会删除其背景颜色?

c# - 在网格 MVC 中显示对象

c# - Mono 中的 XML 序列化问题

c# - 使用 NPOI 从 Excel 电子表格中检索合并单元格的值

c# - 当鼠标悬停在列标题上时滚动 ListView