Miscellaneous Tips
In this section you’ll find various tips not shown in any other documentation.
An Extension Method for Converting to ObservableCollection
As you know, the ObservableCollection
type is the most appropriate object for use when working with data-binding in WPF. It’s not uncommon that an application needs to retrieve data via LINQ
queries; these are of type IEnumerable(Of T)
or IQueryable(Of T)
, and they don’t offer an opportunity to convert the query result directly into an ObservableCollection
. Of course, you can write specific code to convert the query result; one convenient way is by creating an extension method.
The Visual Basic version of the code looks like this:
Imports System.Runtime.CompilerServicesImports System.Collections.ObjectModel ...
Get Hidden WPF: Secrets for Creating Great Applications in Windows Presentation Foundation now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.