2

Resources部分中创建CollectionViewSource时,是否在资源初始化时(即,在登录的持有者为Resources时)或绑定了数据时加载了集合Source延迟加载CollectionViewSource?

是否有一种xamly的方式来制作CollectionViewSource延迟加载?递延负荷?明确的负荷?

回答

0

答案是,只要没有请求,CollectionViewSource不会初始化它的Source属性!

这里是我的测试例子:

<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 

结果:项目关闭下,只有当ListView是注释。