wpf CollectionViewSource 是如何工作的?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15319423/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How does CollectionViewSource work?
提问by Amin
Can anyone tell me how I should set the right property in CollectionViewSource in XAML on Windows 8?
谁能告诉我应该如何在 Windows 8 上的 XAML 中的 CollectionViewSource 中设置正确的属性?
<CollectionViewSource x:Name="itemsViewSource"
Source="{Binding Items}"
d:Source="{Binding AllTasks, Source={d:DesignInstance Type=data:TaskItems, IsDesignTimeCreatable=True}}"/>
x:name is the Name of the object. What's source? What's the difference between d:Source and Source? Can anyone explain it to me?
x:name 是对象的名称。来源是什么?d:Source 和 Source 有什么区别?谁能给我解释一下?
回答by Viv
MSDN Documentationfor this is pretty good.
这方面的 MSDN 文档非常好。
As the documentation suggests Sourceis the collection object your pointing to. Example ObservableCollection<T>
正如文档所暗示的,Source是您指向的集合对象。例子ObservableCollection<T>
The first link also shows a usage example. Basically in plain English CollectionViewSource is used to filter/group/sort data in a list/collection and then use the result in a view
第一个链接还显示了一个使用示例。基本上简单的英语 CollectionViewSource 用于过滤/分组/排序列表/集合中的数据,然后在视图中使用结果
As for your doubt about d:I cannot be sure without seeing your xmlns declaration in your top level element, but assuming defaults d:corresponds to design time data/attributes
至于您对d:我的疑问,如果没有在顶级元素中看到您的 xmlns 声明,我就无法确定,但假设默认值d:对应于设计时数据/属性
It's used to help design and visualise your UI in design time when live data may not be available.
当实时数据可能不可用时,它用于在设计时帮助设计和可视化您的 UI。

