访问控件的父级的父级的数据上下文 [英] Access datacontext of a control's parent's parent

查看:140
本文介绍了访问控件的父级的父级的数据上下文的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

silverlight中是否有任何方法可以访问控件的父级父级的datacontext.我有一个绑定到视图模型的用户控件.用户控件包含绑定到viewmodel属性之一的数据透视控件.因此,枢纽控制项的数据上下文就是该属性.现在,我需要将该枢轴控件项绑定到usercontrol的datacontext的属性(这是一个ICommand)上.但是此属性不适用于数据透视控制项.在WPF中,我可以通过使用 RelativeSource = {RelativeSource AncestorType = {x:Type Grid},AncestorLevel = 1} 来实现.但是AncestorType在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.

推荐答案

您不能在Windows Phone 7 Development中使用AncestorType =(It''不受平台支持.

此解决方案适用于Silverlight 5(SL5)

好吧,我是AncestorType粉丝.删除不必要的代码
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}


在您的XAML上尝试以下代码:


Try this line of code on your XAML:

RelativeSource={RelativeSource AncestorType=Grid, AncestorLevel=1}



希望对您有帮助=)



Hope it helps =)


这篇关于访问控件的父级的父级的数据上下文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆