English 中文(简体)
从数据集中选出一行
原标题:Selecting a certain row from a dataset

我有一个数据集,想在一名世界森林论坛——顾问中显示有 containing。 问题是,控制是一种电路图。 因此,我制作了一个模板,以显示这些价值观,并在我的电路控制中举出多个例子。 目前,电线中的XAML编码类似:

<Label Content="{Binding Path=.[0]}" ContentTemplate="{StaticResource ValueTpl}" />
<Label Content="{Binding Path=.[1]}" ContentTemplate="{StaticResource ValueTpl}" />

因此。 因此,Im能够以特定位置显示第1行。 问题在于,我只能期待正确的秩序。

<Label Content="{Binding Path=.[id=5]}" ContentTemplate="{StaticResource ValueTpl}" />
<Label Content="{Binding Path=.[id=8]}" ContentTemplate="{StaticResource ValueTpl}" />

我读到,应当支持健康倡议,但我无法做到这一点。

最佳回答

如果您有<代码>XPath,则不予支持。

问题回答

Yes, I need to use XPath, but there s more to it.
My mistakes were:
You can t use a DataSet directly but need to wrap it in a XmlDataDocument
Also my problem involved the namespaces. To surpress them you have to set DataSet.Namespace = String.Empty prior to creating the XmlDataDocument.
If you want to use Namespaces you have to create a XmlNamespaceMappingCollection in XAML like this

<UserControl.Resources>
    <XmlNamespaceMappingCollection x:Key="namespace">
        <XmlNamespaceMapping Prefix="ds" Uri="http://tempuri.org/DataSet.xsd" />
    </XmlNamespaceMappingCollection>
</UserControl.Resources>

In order to reference the namespace in the XPath. Simply adding it as xmlns won t work (as opposed to what I expected).
Then referencing a certain row worked like this:

<Label Content="{Binding XPath= //TableName[4] }" />

如果你使用名称空间,你需要参考<代码>。 XmlNamespaceManager

<Label Content="{Binding XPath= //ds:TableName[4] }" Binding.XmlNamespaceManager="{StaticResource namespace}" />

现在,虽然这种非常简单的XPath工作,但增加一项制约因素将导致完全使用CPU,我的方案不会继续:

<Label Content="{Binding XPath= //TableName[Process = 4] }" />
or
<Label Content="{Binding XPath= //ds:TableName[ds:Process = 4] }" Binding.XmlNamespaceManager="{StaticResource namespace}" />

EDIT It seems like the binding must be in OneTime Mode. Simply changing it to

<Label Content="{Binding Mode=OneTime, XPath= //TableName[Process = 4] }" />

使之发挥作用。 我也使用<代码>ContentTemplate,在模板中,约束力可以是TwoWay,但XPath是首要的(例如/Prozess)。





相关问题
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. ...

热门标签