问题描述
亲爱的专家们;)
在我的WPF应用程序中,我有一个名为 Employee 的类,其中包含2个字段: FirstName , LastName .
在我的视图模型中,我有两个可绑定的属性:
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;
我想将我的视图上的TextBlock绑定到当前雇员的FirstName字段;我已经测试了这些语法,但不幸的是没有一个起作用::omg:
a)<TextBlock Text="{Binding Employees[CurrentIndex].FirstName}"/>
b)<TextBlock Text="{Binding Employees[{Binding CurrentIndex}].FirstName}"/>
你能给我解决办法吗?
我不确定,但我认为可以使用CollectionViewSource.但实际上我不想使用它:laugh:
提前谢谢大家,
干杯,
Siavash
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
推荐答案
这篇关于WPF-绑定到集合中的特定元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!