2
在Resources
部分中创建CollectionViewSource
时,是否在资源初始化时(即,在登录的持有者为Resources
时)或绑定了数据时加载了集合Source
?延迟加载CollectionViewSource?
是否有一种xamly的方式来制作CollectionViewSource
延迟加载?递延负荷?明确的负荷?
在Resources
部分中创建CollectionViewSource
时,是否在资源初始化时(即,在登录的持有者为Resources
时)或绑定了数据时加载了集合Source
?延迟加载CollectionViewSource?
是否有一种xamly的方式来制作CollectionViewSource
延迟加载?递延负荷?明确的负荷?
答案是,只要没有请求,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
是注释。