gpt4 book ai didi

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

转载 作者:数据小太阳 更新时间:2023-10-29 02:30:43 24 4
gpt4 key购买 nike

有没有办法在 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com