如何获取ContextMenu的所有者(从Silverlight 4工具包)? [英] How to get the Owner of the ContextMenu (from Silverlight 4 toolkit)?

查看:89
本文介绍了如何获取ContextMenu的所有者(从Silverlight 4工具包)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我从Silverlight 4 Toolkit使用ContextMenu时,我想获取ContextMenu实例的Owner,但是它不可用,因为在ContextMenu类中,Owner是一个内部属性.例如,我在边框内放置了一个矩形.当我右键单击一个Rectangle时(然后会出现一个上下文菜单),我需要更改Rectangle Border的厚度以指示Rectangle是父Grid的当前元素.所以我尝试使用ContextMenu.Loaded事件(通过sender参数获取ContextMenu),但无法获取该ContextMenu的所有者(即带有边框的Rectangle).我需要那个所有者来增加其边框的粗度.请帮助我找到解决方法.

When I use ContextMenu from Silverlight 4 Toolkit I want to get ContextMenu instance's Owner, but it's not available since in ContextMenu class Owner is an internal property. For example, I have a Rectangle put inside a Border. When I right-click a Rectangle (and a context menu appears) I need to change the Rectangle Border's thickness to indicate that the Rectangle is the current element of the parent Grid, for example. So I try to use ContextMenu.Loaded event where I get the ContextMenu (through the sender parameter), but I can't get the Owner of that ContextMenu (i.e. the Rectangle with its Border). And I need that Owner to make its Border thicker. Please help me find the way to do that.

推荐答案

我发现的唯一收获是从后面的代码中将ContextMenu的DataContext设置为所需的元素.然后通过该DataContext属性解决在上下文菜单上打开的元素.

The only soultion I found was to set ContextMenu's DataContext to the needed element from code behind. And then to address the element on which the context menu was opened throught that DataContext property.

这篇关于如何获取ContextMenu的所有者(从Silverlight 4工具包)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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