Reputation: 14426
I have this xaml code:
<Common:LayoutAwarePage.Resources>
<CollectionViewSource x:Name="cvs" IsSourceGrouped="true" />
</Common:LayoutAwarePage.Resources>
<Grid>
<Full:TestSnapPage Name="MainView" />
...
From within the codebehind of the UserControl, how can i access the CollectionViewSource?
Upvotes: 0
Views: 2387
Reputation: 30728
Bind collectionviewsource
to Tag and access it from code behind
< Full:TestSnapPage Name="MainView" Tag="{Binding Source={StaticResource cvs}}"/>
Walk up to Parent page, and access resources in code behind
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;
}
Use MVVMLight framework for communication between views (or between view models).
Upvotes: 2