开发者

binding to a linq query, silverlight 4

I would like to know if binding a control in Silverlight, to linq expression is same开发者_如何学Go as binding to an observable collection ? I have a treeview which as of now I'm binding to an observable collection. Then I learned about linq expressions and it seemed by using the linq query i can totally get rid of this collection and generate it using the query but i'm not sure if this generated result from the linq query will get updated on the fly and pass the updates to the UI?

for example i have a list of employees, i created an observable collection of "employees who were managers" and used that as the itemsource for the tree. Whenever new employees were added and if they were managers they would get added to the manager collection and the tree would update. Now using linq i can generate a list of employees who are managers using a query but i don't have means to test if this will also get updated when new employees who are managers are added to the employees collection.

class EmployeeCollection : IEnumerable<Employee>, INotifyCollectionChanged
{
 private List<Employee> empColl;
// private ObservableCollection<Employee> managerCollection;  Not needed now
}

managerTreeView.ItemsSource = from Employee in EmployeeCollection where Employee.isManager select Employee;

Thanks


LINQ results aren't live collections, so updates to the source (in the linq query) won't trigger the query results to reevaluate. Hence, you won't have your desired behavior.

Hope this helps :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜