Click here to Skip to main content
15,886,017 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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

1 solution

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:
XML
RelativeSource={RelativeSource AncestorType=Grid, AncestorLevel=1}


Hope it helps =)
 
Share this answer
 
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

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900