Click here to Skip to main content
12,395,191 members (63,686 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: Mobile XAML Silverlight
Is there is any way in silverlight to access datacontext of a control's parent's parent. I have a user control bound to a viewmodel. User control contains a pivot control bound to one of viewmodel's property. So the pivot control item's datacontext is that property. Now i need to bind that pivot control item to on of usercontrol's datacontext's property(Which is an ICommand). But this property is not available to the pivot control item . In WPF i can achieve this by using RelativeSource={RelativeSource AncestorType={x:Type Grid},AncestorLevel=1}. But AncestorType is not avialble in silverlight.
Thanks in advance and sorry for the long question.
Posted 16-Jul-12 20:23pm
aajeesh1.3K

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

You can't use AncestorType in Windows Phone 7 Development =( It's not supported by the platform.

This solution works on Silverlight 5 (SL5)

Well I'm an AncestorType fan. Remove innecesary code
{x:Type Grid}
Try this line of code on your XAML:
RelativeSource={RelativeSource AncestorType=Grid, AncestorLevel=1}

Hope it helps =)
  Permalink  
v3
Comments
aajeesh 23-Jul-12 4:50am
   
Thanks for answering, but as i said in my question AncestorType is not available in silverlight.
Christian Amado 23-Jul-12 8:46am
   
I use AncestorType on Silverlight. What version of Silverlight are you using?
aajeesh 24-Jul-12 0:31am
   
I use version 4.
Christian Amado 24-Jul-12 6:40am
   
May be doesn't work on SL4. How about upgrade to SL5? Let me try this on SL4. What about get your desired control via code behind? Or you needed only on xaml?
aajeesh 25-Jul-12 0:26am
   
It is a windows phone 7 application, so i cannot use SL5.I have already done this using code behind. But just wondering if it can be done by using xaml only
Christian Amado 25-Jul-12 6:52am
   
You can't use AncestorType in Windows Phone 7 Development =( It's not supported by the platform. Sorry =(

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160721.1 | Last Updated 25 Jul 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100