Programming - Bindable LINQ


Bindable LINQ is a set of extensions to LINQ that add data binding and change propagation capabilities to standard LINQ queries.

Suppose you wrote the following LINQ to Objects query:

ObservableCollection<Contact> contacts = new ObservableCollection<Contact>();
itemsControl.ItemsSource = from c in contacts
where c.Name.StartsWith("P")
select c;
contacts.Add(new Contact() { Name = "Omar" });
contacts.Add(new Contact() { Name = "Paul" });

Developers familiar with Windows Presentation Foundation or Silverlight know that the ObservableCollection<T> class is designed to propagate change; that is, it raises CollectionChanged events when items are added to the list. However, if you wrote the code above, you would find that neither Omar nor Paul appear on the screen. Why?

It turns out that the objects returned by a LINQ to Objects query do not provide CollectionChanged events. The out of the box LINQ experience makes it difficult for rich client developers to display changes to data while simultaneously using LINQ.

ObservableCollection<Contact> contacts = new ObservableCollection<Contact>();
itemsControl.ItemsSource = from c in contacts.*AsBindable()*
where c.Name.StartsWith("P")
select c;
contacts.Add(new Contact() { Name = "Omar" });
contacts.Add(new Contact() { Name = "Paul" });

Bindable LINQ will detect that the query relies on the Text property of the TextBox object, textBox1. Since the TextBox is a WPF control, Bindable LINQ knows to subscribe to the TextChanged event on the control.
The end result is that as the user types, the items in the query are re-evaluated and the changes appear on screen.

and
More info on BINDABLE LINQ can be found here.


and

and

and

Home | Privacy Policy | Site Map | Links | Company | Contact Us | Arena           

We provide cutting edge software development, consultancy and web design services            

There are currently 543 user(s) with 33597 hits.