Answer the question
In order to leave comments, you need to log in
How to create an XPath query for Polyline.Points?
Help me to make an XPath query, I can't do it for a day already.
There is XML
<Root>
<Chart>
<Title>График 1</Title>
<Points Color="Black">
<Point Value="1 1 10 10"/>
<Point Value="2 2 20 20"/>
<Point Value="3 3"/>
</Points>
</Chart>
<Chart>
<Title>График 2</Title>
<Points Color="Green">
<Point Value="1 1 10 10"/>
<Point Value="2 2 20 20"/>
<Point Value="3 3"/>
</Points>
</Chart>
</Root>
<Polyline Points="{Binding XPath=//Root/Chart/Points/Point/@Value}" />
Answer the question
In order to leave comments, you need to log in
Unfortunately, it is not possible to bind an XPath query that returns several nodes to some property of a type that is not related to the XML structure of the document (for example, to a property of the string type). this will require the aggregation of this set of nodes into a single value (string), and it is not clear how to do this aggregation in the general case. Those. it is not clear how to collect ONE row from multiple Value attribute values.
There are two ways I can recommend you:
1) turn ALL the contents of the Points node into a single string. Here is a working version:
<Window x:Class="PolygonTest.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<XmlDataProvider x:Key="ChartData">
<x:XData>
<Root xmlns="">
<Chart>
<Title>График 1</Title>
<Points Color="Black">
1,1 10,10
40,30 20,20
15,87
</Points>
</Chart>
</Root>
</x:XData>
</XmlDataProvider>
</Window.Resources>
<Grid Name="grid" DataContext="{Binding Source={StaticResource ChartData}}">
<Polygon Name="polygon" Points="{Binding XPath=/Root/Chart[1]/Points}" Stroke="#FFD33D3D" />
</Grid>
</Window>
Have you tried "Root/Chart/Points/ Point /@Value" with "Root/Chart/Points/@Value"?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question