开发者

Lazy/deferred loading of a CollectionViewSource?

When you create a CollectionViewSource in the Resources section, is the set Source loaded when the resources are initalized (i.e. when the Resources holder is inited) or when data is bound?

Is there a xamly way to make a CollectionViewSo开发者_开发百科urce lazy-load? deferred-load? explicit-load?


The answer is, that the CollectionViewSource does not initialize its Source property as long as not requested!

Here is my test example:

<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 shuts-down only when the ListView is uncommented.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜