WPF xml

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Rick

    WPF xml

    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>Fi rst profile</profilename>
    ...
    </profile>
    ... other profile nodes
    </profiles>

    In the Windows.Resourc es node of the xaml I have:

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

    and in the combobox I have:

    <ComboBox Margin="5" Name="cbProfile s" Width="240" IsEditable="Tru e"
    ToolTip="Select database profile"
    VerticalContent Alignment="Cent er"
    ItemsSource="{B inding Source={StaticR esource xmldata},
    XPath=profilena me }" 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

  • Martin Honnen

    #2
    Re: WPF xml

    Rick wrote:
    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>Fi rst profile</profilename>
    ...
    </profile>
    ... other profile nodes
    </profiles>
    >
    In the Windows.Resourc es node of the xaml I have:
    >
    <XmlDataProvide r x:Key="xmldata" Source="c:/temp/xmlData.xml"
    XPath="profiles/profile" />
    >
    and in the combobox I have:
    >
    <ComboBox Margin="5" Name="cbProfile s" Width="240" IsEditable="Tru e"
    ToolTip="Select database profile"
    VerticalContent Alignment="Cent er"
    ItemsSource="{B inding Source={StaticR esource
    xmldata}, XPath=profilena me }" 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
    <profilenamenod es.
    I think you want

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

    and

    <ComboBox Margin="5" Name="cbProfile s" Width="240" IsEditable="Tru e"
    ToolTip="Select database profile"
    VerticalContent Alignment="Cent er"
    ItemsSource="{B inding Source={StaticR esource
    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

    Comment

    Working...