Bind WPF to an XPath-accessible Element Property Value

I would like to bind a value only available with XPath from an element property.

An element is a ComboBox populated from some XML, and its property is SelectedItem. SelectedItem points to an XML element, and I would like to bind it to the value of the child element within it that can be accessed using XPath.

XAML looks like this:

      <StackPanel Orientation="Vertical" Margin="10,10">
        <StackPanel Orientation="Horizontal">
          <Label>Partner</Label>
          <ComboBox Name="Partner" Margin="10,0" 
                    ItemsSource="{Binding XPath=/Root/Tables/Partners/row}" 
                    ItemTemplate="{StaticResource Partner}"/>
        </StackPanel>
        <Button Margin="25,15" Name="Submit" Width="100" Height="30" IsDefault="True"
                CommandParameter="{Binding ElementName=Partner, Path=SelectedItem}">
                Okay
        </Button>
      </StackPanel> 

The source XML is as follows:

<Root>
  <Tables>
    <Partners>
      <row>
        <PartnerID>1</PartnerID>
        <Name>FooBar.Com</Name>
      </row>
      <row>
      .
      .
      .
      </row>
    </Partners>
  </Tables>
</Root>

My problem is that Button CommandParameter is an XmlElement binding that has too much information. I would like the CommandParameter to refer to a child, sort of like if I could specify additional granularity with "XPath = PartnerID" to return an integer value that really interests me.

+3
1

, . , DataContext combobox SelectedItem, CommandParameter XPath, :

<Button DataContext="{Binding ElementName=Partner, Path=SelectedItem}" 
        Margin="25,15" Name="Submit" Width="100" Height="30" IsDefault="True"
        CommandParameter="{Binding XPath=PartnerID/text()}">Okay</Button>
+6

All Articles