Ribbon菜单,这个大家肯定不会陌生,除非黑科技 - -#,不然任何一款插件开发完成后都需要给用户准备界面操作菜单,如下图所示。
创建菜单的方式有两种:
像SDK Sample中的例子一样,硬核写在代码中通过外部配置文件灵活的生成菜单用第一种方式写过菜单的开发者应该深有体会,硬核写实在太麻烦了,菜单一多,调整按钮位置都是很需要耐心的事情,而且每次菜单的修改都会导致需要重新发布程序,哪怕是敲错了一个文字。
你的程序经过 编译、打包、加密、发布 一套流程下来突然发现菜单的一个文本写错了,这不抽自己几下都对不起浪费的时间... ...
如果是做成外部配置,这些都不是问题,它极大的提高了菜单配置的灵活性,而且一劳永逸,每个不同的项目都可用一套菜单服务,如果你安装的其他公司的插件,可以在安装目录下找找是否有菜单的配置文件。
上图的菜单就是用下面的xml配置完成的:
<?xml version="1.0"?> <AddinApp xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <HDTabs> <HDTab Name="测试菜单配置"> <Panels> <HDPanel Name="Panel_1"> <Items> <HDRibbonItem xsi:type="HDPushButton" Name="CmdHDPushButton1" Text="点我" CmdClass="Encode.Cmds.CmdLogin" ImageBig="Icon\CmdLogin.png"/> <HDRibbonItem xsi:type="HDStackedItem"> <Items> <HDRibbonItem xsi:type="HDPushButton" Name="CmdHDPushButton2" Text="StackedItem1" CmdClass="Encode.Cmds.CmdLogin" ImageBig="Icon\CmdLogin.png"/> <HDRibbonItem xsi:type="HDTextBox" Name="HDTextBox"/> <HDRibbonItem xsi:type="HDPulldownButton" Name="HDPulldownButton" Text="HDPulldownButton" ImageBig="Icon\CmdLogin.png"> <Items> <HDRibbonItem xsi:type="HDPushButton" Name="CmdHDPushButton16" Text="点我" CmdClass="Encode.Cmds.CmdLogin" ImageBig="Icon\CmdLogin.png"/> <HDRibbonItem xsi:type="HDPushButton" Name="CmdHDPushButton17" Text="点我" CmdClass="Encode.Cmds.CmdLogin" ImageBig="Icon\CmdLogin.png"/> <HDRibbonItem xsi:type="HDPushButton" Name="CmdHDPushButton18" Text="点我" CmdClass="Encode.Cmds.CmdLogin" ImageBig="Icon\CmdLogin.png" /> </Items> </HDRibbonItem> </Items> </HDRibbonItem> <HDRibbonItem xsi:type="HDSeparator"/> <HDRibbonItem xsi:type="HDSplitButton" Name="HDSplitButton" Text="HDSplitButton" IsSynchronizedWithCurrentItem="true"> <Items> <HDRibbonItem xsi:type="HDPushButton" Name="CmdHDPushButton4" Text="splitButton1" CmdClass="Encode.Cmds.CmdLogin" ImageBig="Icon\CmdLogin.png"/> <HDRibbonItem xsi:type="HDPushButton" Name="CmdHDPushButton5" Text="splitButton2" CmdClass="Encode.Cmds.CmdLogin" ImageBig="Icon\CmdLogin.png"/> <HDRibbonItem xsi:type="HDPushButton" Name="CmdHDPushButton6" Text="splitButton3" CmdClass="Encode.Cmds.CmdLogin" ImageBig="Icon\CmdLogin.png"/> </Items> </HDRibbonItem> </Items> </HDPanel> <HDPanel Name="Panel_2"> <Items> <HDRibbonItem xsi:type="HDSeparator"/> <HDRibbonItem xsi:type="HDRadioButtonGroup" Name="HDRadioButtonGroup"> <Items> <HDToggleButton Name="HDToggleButton1" Text="HDToggleButton1" CmdClass="Encode.Cmds.CmdLogin" ImageBig="Icon\CmdLogin.png"/> <HDToggleButton Name="HDToggleButton2" Text="HDToggleButton1" CmdClass="Encode.Cmds.CmdLogin" ImageBig="Icon\CmdLogin.png"/> <HDToggleButton Name="HDToggleButton3" Text="HDToggleButton1" CmdClass="Encode.Cmds.CmdLogin" ImageBig="Icon\CmdLogin.png"/> </Items> </HDRibbonItem> <HDRibbonItem xsi:type="HDSeparator"/> <HDRibbonItem xsi:type="HDPulldownButton" Name="HDPulldownButton" Text="HDPulldownButton"> <Items> <HDRibbonItem xsi:type="HDPushButton" Name="CmdHDPushButton13" Text="点我" CmdClass="Encode.Cmds.CmdLogin" ImageBig="Icon\CmdLogin.png"/> <HDRibbonItem xsi:type="HDPushButton" Name="CmdHDPushButton14" Text="点我" CmdClass="Encode.Cmds.CmdLogin" ImageBig="Icon\CmdLogin.png"/> <HDRibbonItem xsi:type="HDPushButton" Name="CmdHDPushButton15" Text="点我" CmdClass="Encode.Cmds.CmdLogin" ImageBig="Icon\CmdLogin.png"/> </Items> </HDRibbonItem> <HDRibbonItem xsi:type="HDSeparator"/> <HDRibbonItem xsi:type="HDSlideOut" Name="HDSlideOut"/> <HDRibbonItem xsi:type="HDPushButton" Name="CmdHDPushButton10" Text="点我" CmdClass="Encode.Cmds.CmdLogin" ImageBig="Icon\CmdLogin.png"/> <HDRibbonItem xsi:type="HDPushButton" Name="CmdHDPushButton11" Text="点我" CmdClass="Encode.Cmds.CmdLogin" ImageBig="Icon\CmdLogin.png"/> <HDRibbonItem xsi:type="HDPushButton" Name="CmdHDPushButton12" Text="点我" CmdClass="Encode.Cmds.CmdLogin" ImageBig="Icon\CmdLogin.png"/> </Items> </HDPanel> </Panels> </HDTab> </HDTabs> </AddinApp>具体实现的代码还挺多的,其实写demo也挺花时间,目前正在整理,整理完后可以到QQ群(757293457)下载,仅供参考。