繁体   English   中英

如何在WinRt Xaml中访问UserControl的父资源

[英]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?

  1. collectionviewsource绑定到Tag并从后面的代码访问它

     < Full:TestSnapPage Name="MainView" Tag="{Binding Source={StaticResource cvs}}"/> 
  2. 走到父页面,然后访问后面的代码中的资源

      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; } 
  3. 使用MVVMLight框架进行视图之间(或视图模型之间)的通信。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM