Click here to Skip to main content
15,891,607 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello
following is My xaml code
XML
<ContextMenu x:Key="CMenu"  Visibility="Hidden">

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

 </ContextMenu>

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
Posted
Updated 5-Jan-12 23:36pm
v3

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

C#
CMenu.IsOpen=true;


Hope this helps
 
Share this answer
 
Comments
AmrutaAsbe 6-Jan-12 4:21am    
I already did that...it says cMenu doesnt exist in current text.. that's what confuses me the most couldn't even see in the intellisense..same file just its behind the code
Wayne Gaylard 6-Jan-12 4:27am    
Is it not just a type - you have name the menu CMenu but are trying to access it using cMenu (with small c)
AmrutaAsbe 6-Jan-12 4:32am    
sorry typo in the message..the error is "CMenu doesnt exist in current text"
Sergey Alexandrovich Kryukov 6-Jan-12 5:10am    
No, no! CMenu is the key, but a variable is generated when there is Name defined in XAML.
--SA
AmrutaAsbe 6-Jan-12 5:31am    
I have already tried with x:Name="Menu1"
in cs file I still get error "Menu1 doesnt exist in current context "when I say
Menu1.IsOpen=true;
Menu1.Visibility = Visibility.visible;

I can access the button and ribbon control that I have defined in xaml file but not context menu.
btw I have defined context menu in usercontrol.resources does that make a difference
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

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


Thanks guys for ur time
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900