Click here to Skip to main content
15,892,480 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
Is it possible to get unique values from an xpath query of an xml file in XAML/WPF?
This is the XML file (CurvesIDF.xml):
XML
<?xml version="1.0" encoding="utf-8"?>
<CurvesIDF xmlns="">
  <Curve Name="1">
    <Country>Portugal</Country>
    <Zone>A</Zone>
    <a>5</a>
    10
    <T>5</T>
  </Curve>
  <Curve Name="2">
    <Country>Portugal</Country>
    <Zone>A</Zone>
    <a>45</a>
    -15
    <T>10</T>
  </Curve>
</CurvesIDF>


And this is my XAML markup:
XML
<Window x:Class="CurvesIDF"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300">
    <Window.Resources>
        <XmlDataProvider x:Key="CurvesIDF" Source="CurvesIDF.xml" XPath="CurvesIDF/Curve"/>
    </Window.Resources>

    <Grid DataContext="{Binding Source={StaticResource CurvesIDF}}">
        <Grid.ColumnDefinitions>
            <ColumnDefinition />
            <ColumnDefinition />
        </Grid.ColumnDefinitions>
        <ListBox x:Name="listBox" ItemsSource="{Binding XPath=/CurvesIDF/Curve}" DisplayMemberPath="Zone"/>
    </Grid>
</Window>


The output of this is a list with two entries: "A" and "A", because there are two curves with the same Zone value. I would like to be able to get a list with only one "A" value.

Thanks
Posted
Updated 26-Nov-15 4:30am
v2
Comments
Richard Deeming 26-Nov-15 10:19am    
Almost certainly yes. If you want to know how, you'll need to show us some code.

NB: Don't post the code in a comment. Use the "Improve question" button to update your question with the code. Remember to wrap the code in <pre>...</pre> tags so that it's formatted properly.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900