FindName in Silverlight --- Walk through the viual tree

How do you obtain a reference to an ancestor (within the visual tree) of a Silverlight FrameworkElement, given its name?  The question seems pretty straight forward.  FrameworkElement exposes a method, aptly named FindName, which appears to do just that.  Easy solution, right?  Well....maybe.

 

Using the FindName method works great, as long as the object you're looking for resides within the same XAML namescope as the FrameworkElement.  How do you know if your target object is in the same XAML namescope as your FrameworkElement? 

 

After my research, i found if the control is inside the usercontrols which you are referencing, these kind of controls will not be found by FindName method. While if the target object you are looking for is in the same level of the XAML, they can be found.

 

However, they are still part of the visual tree, so there should be some way to walk the tree down.  FrameworkElement doesn't appear to expose any members to facilitate this type of action.  Still, there must be a way to do it

 

I found a method somewhere for this solution, It will find the object regardless of the XAML namescope.

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值