Exemplo n.º 1
0
 public static XMLItem GetXMLItem(XmlNode xmlNode)
 {
     XMLItem item = new XMLItem(xmlNode);
     item.ItemName = xmlNode.Name;
     item.ItemText = NodeAttr.GetSetNodeAttrValue(xmlNode, Text, Guid.NewGuid() + "");
     item.ItemVisible = NodeAttr.GetSetNodeAttrValue(xmlNode, Visible, "true");
     //单独讨论
     item.ItemChecked = NodeAttr.GetSetNodeAttrValue(xmlNode, Checked, "");
     //remove
     item.ItemDllPath = NodeAttr.GetSetNodeAttrValue(xmlNode, DllPath, "");
     //
     item.ItemBindClass = NodeAttr.GetSetNodeAttrValue(xmlNode, BindClass, "");
     item.ItemItemType = NodeAttr.GetSetNodeAttrValue(xmlNode, ItemType);
     item.ItemRibbonStyle = NodeAttr.GetSetNodeAttrValue(xmlNode, RibbonStyle, "normal");
     item.ItemImage = NodeAttr.GetSetNodeAttrValue(xmlNode, Image, "");
     item.ItemBeginGroup = NodeAttr.GetSetNodeAttrValue(xmlNode, BeginGroup, "false");
     return item;
 }
Exemplo n.º 2
0
        /// <summary>
        /// BarItem的初始化...
        /// </summary>
        /// <param name="xmlItem"></param>
        /// <param name="ctrlAction"></param>
        /// <param name="itemlinks">包含BarItem的父类</param>
        /// <returns></returns>
        public static BarItem GetBarItem(XMLItem xmlItem, CtrlAction ctrlAction, BarItemLinkCollection itemlinks)
        {
            System.Reflection.Assembly asmb = System.Reflection.Assembly.LoadFrom(@"./DevExpress.XtraBars.v14.1.dll");
            Type t = asmb.GetType(xmlItem.ItemItemType);
            BarItem result = Activator.CreateInstance(t) as BarItem;

            if (result != null)
            {
                bool isBeginGroup = xmlItem.ItemBeginGroup == "true";
                itemlinks.Add(result, isBeginGroup);
                result.Name = Guid.NewGuid() + "";
                result.Caption = xmlItem.ItemText;
                result.Visibility = xmlItem.ItemVisible != "false" ? BarItemVisibility.Always : BarItemVisibility.Never;
                result.RibbonStyle = xmlItem.ItemRibbonStyle == "large" ? RibbonItemStyles.Large : RibbonItemStyles.Default;
                if (ctrlAction != null)
                {
                    ctrlAction.BarItem = result;
                    result.ItemClick += (m, n) =>
                    {
                        ctrlAction.Run();
                    };
                }
                result.Tag = ctrlAction;

                try
                {
                    Bitmap bitMap = new Bitmap(xmlItem.ItemImage);
                    result.Glyph = bitMap;
                }
                catch (Exception)
                {
                }

                #region 不同类型按钮的处理
                //5.根据xmlItem.ItemName 来判断类型                
                if (xmlItem.ItemName == XMLItemName.Button)
                {
                    if (xmlItem.ItemChecked != "")
                    {
                        BarButtonItem barButtonItem = result as BarButtonItem;
                        barButtonItem.ButtonStyle = BarButtonStyle.Check;
                        if (xmlItem.ItemChecked == "true")
                        {
                            barButtonItem.Down = true;
                            //if (ctrlAction != null)
                            //    ctrlAction.Run();
                        }
                        else
                            barButtonItem.Down = false;
                    }
                }
                else if (xmlItem.ItemName == XMLItemName.ButtonCheckDropDown)
                {
                    //判断如果有子菜单的情况 XMLItemName.ButtonCheckDropDown,暂时用不到,等换了新版本再说
                }
                else if (xmlItem.ItemName == XMLItemName.ButtonDropDownAct)
                {
                    BarButtonItem barButtonItem = result as BarButtonItem;
                    barButtonItem.ButtonStyle = BarButtonStyle.DropDown;
                    barButtonItem.ActAsDropDown = true;
                }
                else if (xmlItem.ItemName == XMLItemName.ButtonDropDown)
                {
                    BarButtonItem barButtonItem = result as BarButtonItem;
                    barButtonItem.ButtonStyle = BarButtonStyle.DropDown;
                }
                else if (xmlItem.ItemName == XMLItemName.Check)
                {
                    if (xmlItem.ItemChecked != "")
                    {
                        BarCheckItem barCheckItem = result as BarCheckItem;
                        barCheckItem.CheckBoxVisibility = CheckBoxVisibility.BeforeText;
                    }
                }
                else if (xmlItem.ItemName == XMLItemName.SkinRibbonGallery)
                {
                    SkinRibbonGalleryBarItem item = result as SkinRibbonGalleryBarItem;
                    SkinHelper.InitSkinGallery(item);
                }
                #endregion
            }
            return result;
        }