微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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.

 

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐