WPF - 'Relational' Data in XAML Using DataContext

Posted by Andy T on Stack Overflow See other posts from Stack Overflow or by Andy T
Published on 2010-05-28T10:32:03Z Indexed on 2010/05/28 10:41 UTC
Read the original article Hit count: 381

Filed under:
|
|
|

Hi,

Say I have a list of Employee IDs from one data source and a separate data source with a list of Employees, with their ID, Surname, FirstName, etc.

Is it possible in XAML only to get the Employee's name from the second data source and display it next to the ID, using something like this (with the syntax corrected)?..

<TextBlock x:Name="EmployeeID" Text="{Binding ID}"></TextBlock>
<TextBlock Grid.Column="1" DataContext="{StaticResource EmployeeList[**where ID = {Binding ID}**]}" Text="{Binding Surname}"/>

I'm thinking back to my days using XML and XSLT with XPath to achieve the kind of thing shown above. Is this kind of thing possible in XAML? Or do I need to 'denormalize' the data first in code, into one consolidated list?

It seems like it should be possible to do this simple task using XAML only, but I can't quite get my head around how you would switch the DataContext correctly and what the syntax would be to achieve this.

Is it possible, or am I barking up the wrong tree?

Thanks,

AT

© Stack Overflow or respective owner

Related posts about wpf

Related posts about databinding