Click here to Skip to main content
Rate this: bad
good
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 21: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 at 23-Jul-12 4:50am
   
Thanks for answering, but as i said in my question AncestorType is not available in silverlight.
Christian Amado at 23-Jul-12 8:46am
   
I use AncestorType on Silverlight. What version of Silverlight are you using?
aajeesh at 24-Jul-12 0:31am
   
I use version 4.
Christian Amado at 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 at 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 at 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
0 DamithSL 320
1 OriginalGriff 235
2 Afzaal Ahmad Zeeshan 154
3 Sergey Alexandrovich Kryukov 147
4 BillWoodruff 135
0 OriginalGriff 7,510
1 DamithSL 5,494
2 Sergey Alexandrovich Kryukov 4,954
3 Maciej Los 4,936
4 Kornfeld Eliyahu Peter 4,514


Advertise | Privacy | Mobile
Web03 | 2.8.141223.1 | Last Updated 25 Jul 2012
Copyright © CodeProject, 1999-2014
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