Connecting Tech Pros Worldwide Help | Site Map

WPF xml

  #1  
Old October 9th, 2008, 12:45 PM
Rick
Guest
 
Posts: n/a
I'm using WPF with net 3.5 to load the ItemsSource of a combo box from an
xml file.

The xml is setup like this:

<profiles>
<profile>
<profilename>First profile</profilename>
...
</profile>
... other profile nodes
</profiles>

In the Windows.Resources node of the xaml I have:

<XmlDataProvider x:Key="xmldata" Source="c:/temp/xmlData.xml"
XPath="profiles/profile" />

and in the combobox I have:

<ComboBox Margin="5" Name="cbProfiles" Width="240" IsEditable="True"
ToolTip="Select database profile"
VerticalContentAlignment="Center"
ItemsSource="{Binding Source={StaticResource xmldata},
XPath=profilename }" SelectedIndex="0" />

But this only retreives the first profile-profilename for the combobox list.
If I change the XPath of the combobox to //profilename, then I get them all.

What am I not understanding about how this works since I think the XPath of
the XmlDataProvider should be providing a list of <profiles/profilenodes
and then the XPath of the combobox should give me all the <profilename>
nodes.

Regards,

Rick

  #2  
Old October 9th, 2008, 01:45 PM
Martin Honnen
Guest
 
Posts: n/a

re: WPF xml


Rick wrote:
Quote:
I'm using WPF with net 3.5 to load the ItemsSource of a combo box from
an xml file.
>
The xml is setup like this:
>
<profiles>
<profile>
<profilename>First profile</profilename>
...
</profile>
... other profile nodes
</profiles>
>
In the Windows.Resources node of the xaml I have:
>
<XmlDataProvider x:Key="xmldata" Source="c:/temp/xmlData.xml"
XPath="profiles/profile" />
>
and in the combobox I have:
>
<ComboBox Margin="5" Name="cbProfiles" Width="240" IsEditable="True"
ToolTip="Select database profile"
VerticalContentAlignment="Center"
ItemsSource="{Binding Source={StaticResource
xmldata}, XPath=profilename }" SelectedIndex="0" />
>
But this only retreives the first profile-profilename for the combobox
list. If I change the XPath of the combobox to //profilename, then I get
them all.
>
What am I not understanding about how this works since I think the XPath
of the XmlDataProvider should be providing a list of <profiles/profile>
nodes and then the XPath of the combobox should give me all the
<profilenamenodes.
I think you want

<XmlDataProvider x:Key="xmldata" Source="c:/temp/xmlData.xml"
XPath="profiles" />

and

<ComboBox Margin="5" Name="cbProfiles" Width="240" IsEditable="True"
ToolTip="Select database profile"
VerticalContentAlignment="Center"
ItemsSource="{Binding Source={StaticResource
xmldata}, XPath=profile/profilename }" SelectedIndex="0" />

As far as I understand it, the XPath on the XmlDataProvider selects a
single node as the context node, then a relative XPath on the
ItemsSource of the ComboBox selects a list of nodes relative to that
content node.


If you use an absolute XPath like //profilename then you are basically
ignoring the XPath set on the XmlDataProvider.


--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
WPF refer to local member variable for databinding Rick answers 2 October 10th, 2008 01:35 PM
WPF refer to local member variable for databinding Rick answers 2 October 10th, 2008 01:35 PM
Anyone else unhappy with the WPF XAML designer tool in VS.NET? JDeats answers 4 October 7th, 2008 12:25 AM
WPF--a threat to WinForms? raylopez99 answers 23 August 25th, 2008 08:45 PM