The used ad-hoc data binding grid.ItemsSource <- data
silently assumes that the underlying type of items in data
collection allows reasonable rendering of each column value into grid cell. But such assumption is too strong to always be the true!
Bound expression freebase.Commons.Astronomy.Stars |> Seq.take 10
has type
seq<FreebaseData.ServiceTypes.Astronomy.Astronomy.StarData>
. In turn, StarData
properties may be anything. For example, property Also known as
constitutes IEnumerable
by itself, etc. How it should be rendered to a grid cell by default?
If instead we provide a data projection that ensures a default visualization for the binding, then everything would be OK. For example, showing names and distances to five closest to Earth stars can be projected like below:
let astronomy = data.``Science and Technology``.Astronomy
let fiveClosestStars =
query { for e in astronomy.Stars do
where e.Distance.HasValue
sortBy e.Distance.Value
take 5
select (e.Name, e.Distance) }
where fiveClosestStars
now has DataGrid
-palatable type
Linq.IQueryable<string * Nullable<float<Data.UnitSystems.SI.UnitNames.metre>>>
. Then binding
grid.ItemsSource <- fiveClosestStars
yields the expected visual experience
Sun 149597987918.808
Proxima Centauri 4.014161112E+16
Wolf 359 7.3747752E+16
Sirius 8.1461952E+16
Altair 1.58295384E+17