当您在Resources部分中创建CollectionViewSource时,是在初始化资源时(即初始化Resources持有者时)还是在绑定数据时加载集合Source?
有没有一种简单的方法来实现CollectionViewSource延迟加载?延迟加载?显式加载?
发布于 2010-05-10 04:00:38
答案是,只要没有请求,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未被注释时,项目才会关闭。
https://stackoverflow.com/questions/2798501
复制相似问题