Link to home
Start Free TrialLog in
Avatar of jdavey3
jdavey3

asked on

I wand to bind some fields to xml data source using a condition

I want to bind some fields from an xml data file below only where for example username = joe can I do this in xaml
<?xml version="1.0" encoding="utf-8" ?> 
- <UsersData>
- <Users>
  <Username>joe</Username> 
  <Password>test</Password> 
  <Realname>Joe Bloggs</Realname> 
  <Bground>white</Bground> 
  <Font>Times</Font> 
  <Fsize>12</Fsize> 
- <Spell>
  <Sword>cat</Sword> 
  <Finish>y</Finish> 
  </Spell>
- <Spell>
  <Sword>mouse</Sword> 
  <Finish>n</Finish> 
  </Spell>
- <Spell>
  <Sword>horse</Sword> 
  <Finish>n</Finish> 
  </Spell>
  </Users>
- <Users>

Open in new window

Avatar of ZachSmith
ZachSmith
Flag of United States of America image

To get to the specified data you'll need XPath.
Avatar of Martman100
Martman100

This may help. I believe this will retun all the Users where the Username = "joe"
/UsersData/Users[Username = "joe"]/
ASKER CERTIFIED SOLUTION
Avatar of ZachSmith
ZachSmith
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jdavey3

ASKER

/UsersData/Users[Username = "joe"]/

I put the xpath into Blend which produced the following xaml , but it does not work,

<ListBox Width="200" Height="200" Canvas.Left="610" Canvas.Top="251" ItemTemplate="{DynamicResource UsersTemplate1}" ItemsSource="{Binding Mode=OneTime, Source={StaticResource UsersDataDS}, XPath=/UsersData/Users/[@Username\=\&quot;joe\&quot;]}"/>

I was hoping to do the binding in xaml but not sure if I could put a field name into the XPath statement ?

XPath=/UsersData/Users/[@Username=field_enteredusername;] ?