如果 viewSource 是静态资源,何时设置 CollectionViewSource Source 属性
我在 XAML 中得到了以下 CollectionViewSource 定义:
<UserControl.Resources>
<CollectionViewSource x:Key="PersonsViewSource" Source="{Binding AvailablePersons}">
<CollectionViewSource.SortDescriptions>
<scm:SortDescription PropertyName="Surname" Direction="Ascending" />
</CollectionViewSource.SortDescriptions>
</CollectionViewSource>
</UserControl.Resources>
我有一个绑定到此 CVS 的组合框,并且想从这样的代码访问视图:
(Resources["PersonsViewSource"] as CollectionViewSource).View
但是,即使我尝试在 InitializeComponent()
之后在构造函数中访问它或在 Loaded 事件
处理程序中 View &源仍然是null
。
当应用程序在浏览器中向我显示时,尽管绑定已经发生,并且如果我现在在某处放置断点,则查看&amp;来源现在不为空。
那么 Source 到底是什么时候设置的呢?我在哪里可以访问加载应用程序阶段的视图?
也许这是一个一般性的绑定问题,与视图源无关,静态资源绑定何时设置?
I got following CollectionViewSource definition in XAML:
<UserControl.Resources>
<CollectionViewSource x:Key="PersonsViewSource" Source="{Binding AvailablePersons}">
<CollectionViewSource.SortDescriptions>
<scm:SortDescription PropertyName="Surname" Direction="Ascending" />
</CollectionViewSource.SortDescriptions>
</CollectionViewSource>
</UserControl.Resources>
I got a combobox bound to this CVS and would like to access the View from code like this:
(Resources["PersonsViewSource"] as CollectionViewSource).View
However even if I try to access it in constructor after InitializeComponent()
or in Loaded event
handler View & Source are still null
.
When application is shown to me in browser though binding has already taken place and if I now put a breakpoint somewhere view & source are not null now.
So when exactly is Source set? Where can I access the view on the stage of loading my application?
Maybe this is a general binding question not really regarding viewsource, when is static resource binding set?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
绑定是在初始化期间设置的,因为此行已被解析:
但该绑定指向当时 AvailablePersons 属性中存在的任何数据。。它将保持为空,直到任何相关的异步加载完成。
使用 Silverlight,您通常对数据加载事件感兴趣,而不是可视化树何时显示。
您能否告诉我们更多有关如何获取AvailablePersons 数据的信息?
The binding is set during Initialise, as this line is parsed:
but that binding points to whatever data exists in the AvailablePersons property at that time. It will remain empty until any related asynchronous load completes.
With Silverlight, you are generally interested in data loaded events, rather than when the visual tree goes on display.
Can you tell us more about how you are fetching the data for AvailablePersons?