Click here to Skip to main content
15,891,316 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi dear experts ;)

In my WPF app, I have a class called Employee with 2 fields: FirstName, LastName.
In my view model, I have two bindable properties:
ObservableCollection<Employee> Employees;<br />
int CurrentIndex;


I want to bind a TextBlock on my view to the FirstName field of current employee; I've tested these syntaxs, but unfortunately none worked: :omg:

a) <TextBlock Text="{Binding Employees[CurrentIndex].FirstName}"/>
b) <TextBlock Text="{Binding Employees[{Binding CurrentIndex}].FirstName}"/>

Can you give me any solution?
I'm not sure but I think it's possible to use CollectionViewSource; but actually I prefer not to use it :laugh:

Thank you all in advance,
Cheers,
Siavash
Posted
Updated 9-Feb-11 4:54am
v2

It would be far more easier to add a new property to your view-model called CurrentEmployee which returns Employees[CurrentIndex].
 
Share this answer
 
Thanks Nishant :)
You're right;
I didn't want to maintain an extra reference for that; but it seems it's unavoidable.

Cheers,
Siavash
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900