wpf - How to Uncheck Menuitem isCheked property in MenuItemClick event -
i able check menuitem not able uncheck , more on showing previous check in menuitem. once click on menuitem doesn't uncheck previous menuitem. i'm adding menuitem code.
private void onmenuitemclick(object sender, routedeventargs e) { routedeventargs args = e routedeventargs; menuitem item = args.originalsource menuitem; string header = item.header.tostring(); if (header == "b1") { btnmenu.content = header; item.ischecked=true; } else if (header == "a1") { btnmenu.content = header; item.ischecked=true; } }
i applying same menuitems , event handler 4 buttons.so if select 1 menuitem first button show check on menuitem,the checked menu item show appear when click on second button.how can achieve this?..any suggestion.
edit:xaml
<stackpanel grid.row="11" orientation="horizontal" flowdirection="lefttoright"> <button name="btnphone" content="mobile" horizontalalignment="left" verticalalignment="top" margin="0 0 12 0" width="85" click="onbtnphoneclick"></button> <button horizontalalignment="left" name="ddbtnphone" verticalalignment="top" width="25" click="onddbtnphoneclick" > <button.content> <path x:name="btnarrow1" margin="4" verticalalignment="center" width="10" fill="#ff527db5" stretch="uniform" horizontalalignment="right" data="f1 m 301.14,-189.041l 311.57,-189.041l 306.355,-182.942l 301.14,-189.041 z "/> </button.content> <button.contextmenu> <contextmenu x:name="cmphone"> </contextmenu> </button.contextmenu> </button> </stackpanel> <stackpanel grid.row="12" orientation="horizontal" flowdirection="lefttoright"> <button name="btnhome" content="business" horizontalalignment="left" margin="0,0,12,5" width="85" click="onbtnhomeclick" /> <!--<exttoolkit:dropdownbutton x:name="ddbtnhome" verticalalignment="top" width="30" horizontalalignment="right" margin="0 0 30 0" height="20"/>--> <button horizontalalignment="left" name="ddbtnhome" verticalalignment="bottom" width="25" click="onddbtnhomeclick" margin="0,0,0,5" > <button.content> <path x:name="btnarrow2" margin="4" verticalalignment="center" width="10" fill="#ff527db5" stretch="uniform" horizontalalignment="right" data="f1 m 301.14,-189.041l 311.57,-189.041l 306.355,-182.942l 301.14,-189.041 z "/> </button.content> <button.contextmenu> <contextmenu name="cmhome"> </contextmenu> </button.contextmenu> </button> </stackpanel> <stackpanel grid.row="13" orientation="horizontal" flowdirection="lefttoright"> <button name="btnmobile" content="home" horizontalalignment="left" verticalalignment="top" margin="0 0 12 0" width="85" click="onbtnmobileclick"></button> <!--<exttoolkit:dropdownbutton x:name="ddbtnmobile" verticalalignment="top" width="30" horizontalalignment="right" margin="0 0 30 0" height="20"/>--> <button horizontalalignment="left" name="ddbtnmobile" width="25" click="onddbtnmobileclick" margin="0,0,0,5" > <button.content> <path x:name="btnarrow3" margin="4" verticalalignment="center" width="10" fill="#ff527db5" stretch="uniform" horizontalalignment="right" data="f1 m 301.14,-189.041l 311.57,-189.041l 306.355,-182.942l 301.14,-189.041 z "/> </button.content> <button.contextmenu> <contextmenu name="cmmobile"> </contextmenu> </button.contextmenu> </button> </stackpanel> <stackpanel grid.row="14" orientation="horizontal" flowdirection="lefttoright"> <button name="btnfax" content="business fax" horizontalalignment="left" verticalalignment="top" margin="0 0 12 0" width="85" click="onbtnfaxclick"></button> <!--<exttoolkit:dropdownbutton x:name="ddbtnfax" verticalalignment="top" width="30" horizontalalignment="right" margin="0 0 30 0" height="20"/>--> <button horizontalalignment="left" name="ddbtnfax" verticalalignment="bottom" width="25" click="onddbtnfaxclick" margin="0,0,0,5" > <button.content> <path x:name="btnarrow4" margin="4" verticalalignment="center" width="10" fill="#ff527db5" stretch="uniform" horizontalalignment="right" data="f1 m 301.14,-189.041l 311.57,-189.041l 306.355,-182.942l 301.14,-189.041 z "/> </button.content> <button.contextmenu> <contextmenu name="cmfax"> </contextmenu> </button.contextmenu> </button> </stackpanel>
this how adding menuitems each contextmenu.
private void addmenuitems(contextmenu cmenu, button btnname) { if (cmenu.items.count == 0) { mnitem = new menuitem(); mnitem.header = "b1"; cmenu.items.add(mnitem); mnitem = new menuitem(); mnitem.header = "a1"; cmenu.items.add(mnitem); mnitem = new menuitem(); mnitem.header = "b2"; cmenu.items.add(mnitem); mnitem = new menuitem(); mnitem.header = "a2"; cmenu.items.add(mnitem); cmenu.addhandler(menuitem.clickevent, new routedeventhandler(onmenuitemclick)); cmenu.addhandler(menuitem.mouseleftbuttonupevent, new mousebuttoneventhandler(onmousebuttonupeventclick)); btncommon = btnname; }
not sure understand want. if want menuitems checked mutually exclusive should check post: mutually exclusive checkable menu items?
Comments
Post a Comment