我已经渲染了两个带有图标的菜单项.根据某些条件,我想以编程方式启用和禁用菜单项,并且工作正常.我的问题是,当菜单项处于禁用状态时,该图标似乎没有被禁用,它与启用菜单项时的状态保持不变. 但是正如我在IDE中看到的那样菜单项处于禁用状态时,图标的颜色也会改变.我是否需要根据菜单的状态动态更改图标,或者我缺少要做的事情? 可以吗?正文可以帮助我解决它. 下面是代码.
I have rendered two menu items with icons. Based on some condition I want to enable and disable the menu items programatically and it is working fine. My problem is that when the menu item is in disabled state the icon does not seems to be disabled,it remains same as it was in when menu item was enabled.But as I have seen in the IDE the icon color also change when the menu item is in disabled state.Do I need to change the Icon dynamically based on the state of menu or I am missing something to do?Can any body help me to solve it.Following are the code.
<按钮guid =" guidVSPackage1CmdSet" id ="stdToolbarDisConnectBtn";优先级="0x0100&"; type =按钮"> <父guid ="guidVSPackage1CmdSet"; id ="KovairStdToolBarGroup"; /> .<!-< Icon guid ="disconnectImage" id ="bmpPic1" />-> .< Icon guid ="guidImages" id ="bmpPicX"; /> < CommandFlag> DefaultDisabled</CommandFlag> < ButtonText>与Omnibus服务器断开连接</ButtonText> ; id ="KovairMenuGroup"优先级="0x0500&"> 父guid ="guidVSPackage1CmdSet"; id =" KovairMenu"/</Group> < Menu guid =" guidVSPackage1CmdSet" id ="KovairMenu"优先级="0x700" type ="Menu"> <父guid ="guidSHLMainMenu"; id ="IDG_VS_MM_TOOLSADDINS" /> <字符串> < ButtonText>& amp; Kovair OmniBus</ButtonText> > 代码以禁用菜单:-
OleMenuCommandService
<Button guid="guidVSPackage1CmdSet" id="stdToolbarDisConnectBtn" priority="0x0100" type="Button"> <Parent guid="guidVSPackage1CmdSet" id="KovairStdToolBarGroup" /> <!--<Icon guid="disconnectImage" id="bmpPic1" />--> <Icon guid="guidImages" id="bmpPicX" /> <CommandFlag>DefaultDisabled</CommandFlag> <CommandFlag>DynamicVisibility</CommandFlag> <Strings> <CommandName>stdToolbarDisConnectBtn</CommandName> <ButtonText>Disconnect From Omnibus Server</ButtonText> </Strings> </Button> <Group guid="guidVSPackage1CmdSet" id="KovairMenuGroup" priority="0x0500"> <Parent guid="guidVSPackage1CmdSet" id="KovairMenu"/> </Group><Menu guid="guidVSPackage1CmdSet" id="KovairMenu" priority="0x700" type="Menu"> <Parent guid="guidSHLMainMenu" id="IDG_VS_MM_TOOLSADDINS" /> <Strings> <ButtonText>&Kovair OmniBus</ButtonText> </Strings> </Menu>code to disable the menu:-
OleMenuCommandService
mcs = GetService( typeof ( IMenuCommandService )) 另存为 OleMenuCommandService ;
CommandID
mcs = GetService(typeof(IMenuCommandService)) as OleMenuCommandService;
CommandID
cmdID = 空 ;
cmdID = null;
MenuCommand menuCmd = 空 ;
MenuCommand menuCmd = null;
cmdID =
cmdID =
新 CommandID ( GuidList .guidVSPackage1CmdSet,( int ) PkgCmdIDList .activityLogCommand);
new CommandID(GuidList.guidVSPackage1CmdSet, (int)PkgCmdIDList.activityLogCommand);
如果 (menuCmd!= 空 )
{ menuCmd.Enabled =
if (menuCmd != null)
{menuCmd.Enabled =
false ; } 感谢, Ankesh.
menuCmd = mcs.FindCommand(cmdID);
menuCmd = mcs.FindCommand(cmdID);
推荐答案
您好,Ankesh772, 您是要隐藏此菜单项吗?在这种情况下,可以将MenuItem的Visiable属性指定为false,有关更多信息,请通过以下链接引用MenuItem的属性: msdn.microsoft/en-us/library/systemponentmodel.design.menucommand_properties.aspx 如果我误解了您,或者您有任何疑问,请让我知道. 最诚挚的问候,南希 Hi Ankesh772,Do you mean you want to hide this menuitem if you have disabled it? If this is in the case, you can specify Visiable property of MenuItem to false, for more information, please refer to the properties of MenuItem with following link:msdn.microsoft/en-us/library/systemponentmodel.design.menucommand_properties.aspxIf I misnuderstood you, or you have any questions, please let me know.Best Regards,Nancy
更多推荐
禁用菜单项时出现问题
发布评论