Lazy / lazy loading CollectionViewSource?
When you create CollectionViewSource
in a section Resources
, is the collection loaded Source
when the resources are initialized (i.e. when the owner is Resources
enabled) or when the data is bound?
Is there a xamly way to do CollectionViewSource
lazy loading? deferred loads? Explicit loads?
a source to share
The answer is that it CollectionViewSource
doesn't initialize the property Source
if not requested!
Here's my test case:
<Window
x:Class="MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:src="clr-namespace:WpfApplication2">
<Window.Resources>
<CollectionViewSource x:Key="mySource">
<CollectionViewSource.Source>
<src:Collection />
</CollectionViewSource.Source>
</CollectionViewSource>
</Window.Resources>
<!--ListView ItemsSource="{Binding Source={StaticResource mySource}}"/-->
</Window>
Imports System.Collections.ObjectModel
Imports System.ComponentModel
Public Class Collection : Inherits ObservableCollection(Of String)
Public Sub New()
If Not DesignerProperties.GetIsInDesignMode(New DependencyObject) Then End
For i = 1 To 10
Add("Item " & i)
Next
End Sub
End Class
Result: the project is disabled only when ListView
uncommented.
a source to share