代码后面的上下文菜单 [英] Context menu behind the code

查看:58
本文介绍了代码后面的上下文菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好
以下是我的xaml代码

Hello
following is My xaml code

<ContextMenu x:Key="CMenu"  Visibility="Hidden">

<MenuItem Header="Select All" Command="{x:Static s:vas.SelectAll}"/>

 </ContextMenu>


单击btn1后,我希望上下文菜单可见
我已经为按钮单击编写了事件(它还有其他功能),但不确定如何更改代码后面的上下文菜单的属性

希望我清楚
在此先感谢


After a btn1 is clicked I want the context menu to be visible
I have already written the event for button click(its does other stuffs)but not sure how to change the property of the context menu behind the code

Hope I am clear
Thanks in advance

推荐答案

您可以使用contextmenu的IsOpen属性打开和关闭后面代码中的菜单.

You can use the IsOpen property of the contextmenu to open and close the menu in the code behind.

CMenu.IsOpen=true;



希望这会有所帮助



Hope this helps


我猜想它丢失了usercontrol中的细节.资源是我无法在智能感知中看到它的主要原因(仍然是新的,尽管可能不会影响很大:P)
在代码中检索资源有些不同

我做了这样的事情,现在为我工作

I guess missing out the detail that it was in usercontrol.resource is the main reason why I cannot see it in intellisense (Still new so though might not affect much :P)
To retrieve a resource in code is a a little bit different

I have done something like this and works for me now

object MyMenu =  this.FindResource("CMenu");
((System.Windows.Controls.ContextMenu)(MyMenu)).Visibility = Visibility.Visible;



谢谢你们的时间



Thanks guys for ur time


这篇关于代码后面的上下文菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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