![](/img/trans.png)
[英]WinRT: How to access parent's ItemsSource in DataTemplateSelector of ContentControl
[英]How to access a UserControl's parent resources in WinRt Xaml
我有这个xaml代码:
<Common:LayoutAwarePage.Resources>
<CollectionViewSource x:Name="cvs" IsSourceGrouped="true" />
</Common:LayoutAwarePage.Resources>
<Grid>
<Full:TestSnapPage Name="MainView" />
...
从UserControl的代码隐藏中,我如何访问CollectionViewSource?
将collectionviewsource
绑定到Tag并从后面的代码访问它
< Full:TestSnapPage Name="MainView" Tag="{Binding Source={StaticResource cvs}}"/>
走到父页面,然后访问后面的代码中的资源
var parentPage = GetParentsPage(this); if (parentPage != null) { //parentPage.Resources["cvs"] } private ParentPage GetParentsPage(FrameworkElement @this) { FrameworkElement temp = @this; while (temp.Parent != null) { if (temp.Parent is ParentPage) return temp.Parent as ParentPage; temp = temp.Parent as FrameworkElement; } return null; }
使用MVVMLight框架进行视图之间(或视图模型之间)的通信。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.