WPF – DataContext Virtualization With Paged Services

by Dean 27. April 2010 21:51
Many WPF applications need to handle a very large data collections – maybe the users really need a million rows in their GridView control. The way we cope with this is to ‘virtualize’ the data, and have it available to your control on an ‘as needed’ basis. Most list controls in WPF (including the standard ListView/GridView) include the concept of a ‘viewport’ under the hood. A viewport is a virtual ‘window’ on the underlying data collection, which only requires the data currently being displayed – so if your collection is a million rows, and your ‘viewport’ is only 100 rows high, then you only need 100 rows (although they must be the ‘right’ rows). In addition, if the data collection that is your DataContext implements the non-generic ‘IList’ interface, the viewport will optimize it access to the collection calling the ‘IList.this[index]’ for row enumeration rather than GetEnumerator(). This means that if we create a custom collection that implements the non-generic ‘IList’ interfac... [More]

Tags: , ,

DataBinding | WCF | XAML | WPF

Lightweight ‘O/R Mapping’ in F# Interactive

by Dean 26. April 2010 21:15
I’ve been playing a lot with F# lately, particularly in the area of financial option modelling, which requires quite a lot of number crunching – a perfect scenario for tinkering around in F# interactive. However, I need to get data out of my data store, and use it to create collections of records, that represent the data that I need. This was becoming a little cumbersome, so I thought I’d create a little ORM function to do the trick open System.Data.SqlClient open Microsoft.FSharp.Reflection   let BuildData<'T> (connection:string, command:string) = let conn = new SqlConnection(connection) let comm = new SqlCommand(command,conn) let recordType = typeof<'T> let fieldCount = FSharpType.GetRecordFields(recordType).Length conn.Open() let db = comm.ExecuteReader() let rec populate (reader:SqlDataReader) (l:'T list) = match reade... [More]

Tags: , , ,

F# | DataBinding

F# And MVVM – A Simple ViewModel

by Dean 12. April 2010 20:51
For many years, OOP abstractions and design patterns have been the cornerstones of my development methodology as a senior C# developer in investment banking. However, over the last year or so I have taken quite a shine to Microsoft’s new FP language (F#), not just because purely functional program code is concise powerful and elegant, but because the eclectic mix of functional and OOP paradigms in F# enable me to develop better, faster, stronger and more maintainable applications. In investment banking, the business has been changing fast, and being able to get production quality WPF apps onto the trader desks has been a big priority, and with F# I find myself more able to meet that challenge. The WPF design pattern ‘du jour’ is MVVM. Anyone who’s serious about enterprise-strength development in WPF would have come across this pattern and probably have used it at some point in the recent past. Detailed below is a very basic implementation where :- There is a WPF project that co... [More]

Tags: ,

DataBinding | F# | MVVM

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2010 Dean Chalk's Blog