Beispiel #1
0
 protected override async Task OnStartupAsync()
 {
     //插入RibbonTab
     Mg.Get <IMgRibbon>().InsertRibbonTab(this, new MyTabViewModel());
     //在已有的菜单组中插入菜单按钮
     _groupVm = Mg.Get <IMgRibbon>().GetRibbonGroup(LocalConfig.InsertGroupName);
     if (_groupVm != null)
     {
         _viewBtn = new RibbonButtonViewModel
         {
             ButtonSize = ButtonSize.Large,
             Text       = "我的按钮",
             LargeImage = this.GetAppResPath("Assets\\logo.jpg"),
             SmallImage = this.GetAppResPath("Assets\\logo.jpg"),
             Click      = new RelayCommand(ShowPane)//按钮命令
         };
         _groupVm.Items.Add(_viewBtn);
     }
     else
     {
         Mg.Get <IMgLog>().Warn($"没有找到名称为{LocalConfig.InsertGroupName}的菜单组,无法插入菜单按钮!");
     }
     //注册全局命令,全局命令可以任何地方使用
     Mg.Get <IMgCommand>().Register(this, new CommandInfo("AlertMessage", new RelayCommand(OnAlertMessage)));
     Mg.Get <IMgCommand>().Register(this, new CommandInfo("AlertMessageAsync", new AsyncCommand(OnAlertMessageAsync, CanAlertMessageAsync)));
     await Task.Yield();
 }
Beispiel #2
0
 protected override async Task OnStartupAsync()
 {
     //插入菜单组
     Mg.Get <IMgRibbon>().InsertRibbonTab(this, new MyTabViewModel());
     //在已有的菜单组中插入菜单按钮
     _groupVm = Mg.Get <IMgRibbon>().GetRibbonGroup(LocalConfig.InsertGroupName);
     if (_groupVm != null)
     {
         _viewBtn = new RibbonButtonViewModel
         {
             ButtonSize = ButtonSize.Large,
             Text       = "打开非异步窗口",
             LargeImage = this.GetAppResPath("Assets\\logo.jpg"),
             SmallImage = this.GetAppResPath("Assets\\logo.jpg"),
             Click      = new RelayCommand(ShowWindow) //按钮命令
         };
         _groupVm.Items.Add(_viewBtn);                 //添加到菜单组里
         _viewBtnAsync = new RibbonButtonViewModel
         {
             ButtonSize = ButtonSize.Large,
             Text       = "打开异步窗口",
             LargeImage = this.GetAppResPath("Assets\\logo.jpg"),
             SmallImage = this.GetAppResPath("Assets\\logo.jpg"),
             Click      = new RelayCommand(ShowWindowAsync) //按钮命令
         };
         _groupVm.Items.Add(_viewBtnAsync);                 //添加到菜单组里
     }
     else
     {
         Mg.Get <IMgLog>().Warn($"没有找到名称为{LocalConfig.InsertGroupName}的菜单组,无法插入菜单按钮!");
     }
     await Task.Yield();
 }
Beispiel #3
0
        public static void AddRibbonButtons()
        {
            _exitButton             = new RibbonApplicationMenuItemViewModel("Exit");
            _exitButton.Command     = new RelayCommand(Exit, ReturnTrue);
            _exitButton.ImageSource = PngIcons.GetIcon(IconName.Exit, IconSize.Size32);
            VM.ApplicationMenuItems.Add(_exitButton);



            _globalButton            = new RibbonButtonViewModel("Start tests");
            _globalButton.Command    = new RelayCommand((param) => { }, ReturnTrue);
            _globalButton.LargeImage = PngIcons.GetIcon(IconName.Play, IconSize.Size32);
            VM.AddRibbonButton("Global", "Global", "", _globalButton);

            _clearConfigButton            = new RibbonButtonViewModel("Clear");
            _clearConfigButton.LargeImage = PngIcons.GetIcon(IconName.Clear, IconSize.Size32);
            VM.AddRibbonButton("Configuration", "Configuration", "", _clearConfigButton);
            _saveXmlConfigButton            = new RibbonButtonViewModel("Save XML config");
            _saveXmlConfigButton.LargeImage = PngIcons.GetIcon(IconName.Save, IconSize.Size32);
            VM.AddRibbonButton("Configuration", "Configuration", "XML", _saveXmlConfigButton);
            _loadXmlConfigButton            = new RibbonButtonViewModel("Load XML config");
            _loadXmlConfigButton.LargeImage = PngIcons.GetIcon(IconName.DocumentOpen, IconSize.Size32);
            VM.AddRibbonButton("Configuration", "Configuration", "XML", _loadXmlConfigButton);
            _saveIniConfigButton            = new RibbonButtonViewModel("Save INI config");
            _saveIniConfigButton.LargeImage = PngIcons.GetIcon(IconName.Save, IconSize.Size32);
            VM.AddRibbonButton("Configuration", "Configuration", "INI", _saveIniConfigButton);
            _loadIniConfigButton            = new RibbonButtonViewModel("Load INI config");
            _loadIniConfigButton.LargeImage = PngIcons.GetIcon(IconName.DocumentOpen, IconSize.Size32);
            VM.AddRibbonButton("Configuration", "Configuration", "INI", _loadIniConfigButton);

            _dbButton            = new RibbonButtonViewModel("Start test");
            _dbButton.Command    = new RelayCommand((param) => { }, ReturnTrue);
            _dbButton.LargeImage = PngIcons.GetIcon(IconName.Play, IconSize.Size32);
            VM.AddRibbonButton("Database", "Database", "", _dbButton);

            _startHttpButton            = new RibbonButtonViewModel("Start server");
            _startHttpButton.Command    = new RelayCommand((param) => { }, ReturnTrue);
            _startHttpButton.LargeImage = PngIcons.GetIcon(IconName.Play, IconSize.Size32);
            VM.AddRibbonButton("HttpServer", "HttpServer", "", _startHttpButton);
            _stopHttpButton            = new RibbonButtonViewModel("Stop server");
            _stopHttpButton.Command    = new RelayCommand((param) => { }, ReturnTrue);
            _stopHttpButton.LargeImage = PngIcons.GetIcon(IconName.Close, IconSize.Size32);
            VM.AddRibbonButton("HttpServer", "HttpServer", "", _stopHttpButton);

            _startTcpButton            = new RibbonButtonViewModel("Start test");
            _startTcpButton.Command    = new RelayCommand((param) => { }, ReturnTrue);
            _startTcpButton.LargeImage = PngIcons.GetIcon(IconName.Play, IconSize.Size32);
            VM.AddRibbonButton("TcpServer", "TcpServer", "", _startTcpButton);
            _stopTcpButton            = new RibbonButtonViewModel("Stop test");
            _stopTcpButton.Command    = new RelayCommand((param) => { }, ReturnTrue);
            _stopTcpButton.LargeImage = PngIcons.GetIcon(IconName.Close, IconSize.Size32);
            VM.AddRibbonButton("TcpServer", "TcpServer", "", _stopTcpButton);

            _reportingButton            = new RibbonButtonViewModel("Start test");
            _reportingButton.Command    = new RelayCommand((param) => { }, ReturnTrue);
            _reportingButton.LargeImage = PngIcons.GetIcon(IconName.Play, IconSize.Size32);
            VM.AddRibbonButton("Reporting", "Reporting", "", _reportingButton);
        }
Beispiel #4
0
        public static RibbonButtonViewModel CreateRibbonButton()
        {
            RibbonButtonViewModel buttonVm = new RibbonButtonViewModel()
            {
                Name       = "Name",
                Text       = "测试Button",
                LargeImage = "url",
                ButtonSize = ButtonSize.Large,
            };

            return(buttonVm);
        }
        /// <summary>
        /// 创建Button
        /// </summary>
        public static RibbonButtonViewModel CreateRibbonButton(IApp iApp, string buttonName, string text, Action action)
        {
            var buttonVm = new RibbonButtonViewModel()
            {
                Name       = buttonName,
                Text       = text,
                LargeImage = iApp.GetAppResPath("Assets\\测试图片.png"),
                SmallImage = iApp.GetAppResPath("Assets\\测试图片.png"),
                ButtonSize = ButtonSize.Large,
                Click      = new RelayCommand(action)
            };

            return(buttonVm);
        }
Beispiel #6
0
        protected override async Task OnStartupAsync()
        {
            /*******************采用代码方式创建************************/
            //创建RibbonTab标签
            _tab = RibbonExample.CreateRibbonTab(this, "CodeCreateTab", "代码Tab");
            //创建RibbonGroup 并加入Tab
            _groupOne = RibbonExample.CreateRibbonGroup("CodeCreateGroupOne", "代码Group");
            _tab.Groups.Add(_groupOne);//_tab.Groups.Insert(0,_group);
            //创建RibbonButton 在上述创建的RibbonGroup中加入RibbonButton
            _buttonOne       = RibbonExample.CreateRibbonButton(this, "CodeCreateButton", "代码Button", ShowWindow);
            _buttonOne.Click = new RelayCommand(ShowWindow);//button点击的事件
            _groupOne.Items.Add(_buttonOne);
            //已有的RibbonTab中加入新的RibbonGroup
            var existTab = Mg.Get <IMgRibbon>().GetRibbonTab(_tab.Name);//传入已存在的tabName

            _groupTwo = RibbonExample.CreateRibbonGroup("CodeCreateGroupTwo", "向已有Tab加入的Group");
            existTab.Groups.Add(_groupTwo);                                       //注意如果该Group中没有Item则在界面上不能显示
            //已有的RibbonGroup中加入新的RibbonButton
            var existGroup = Mg.Get <IMgRibbon>().GetRibbonGroup(_groupTwo.Name); //传入已存在的groupName

            _buttonTwo = RibbonExample.CreateRibbonButton(this, "CodeCreateButtonTwo", "向已有Group加入的Button", ShowWindow);
            existGroup.Items.Add(_buttonTwo);

            /*******************采用Xml方式创建************************/
            Mg.Get <IMgRibbon>().InsertRibbonTab(this, new ViewTabViewModel(), 1);
            //已有的RibbonTab中加入RibbonGroup
            _xmlTab   = Mg.Get <IMgRibbon>().GetRibbonTab(LocalConfig.InsertTabName);//可以通过将一些已存在的TabName存在_config.xml里
            _xmlGroup = new ViewGroupViewModel();
            _xmlTab.Groups.Add(_xmlGroup);
            //已有的RibbonGroup中加入RibbonButton
            _xmlGroupTwo = new ViewButtonViewModel();
            //注意:ViewButtonViewModel并不是继承RibbonButtonViewModel,因为RibbonButtonViewModel不支持直接解析XML文件里的<Button>标签
            //因此只能通过外层加上<Group>标签,通过继承RibbonGroupViewModel去解析XML,然后得到Group里的Button组
            _xmlGroup = Mg.Get <IMgRibbon>().GetRibbonGroup(_xmlGroup.Name);
            _xmlGroup.Items.AddRange(_xmlGroupTwo.Items);

            /*******************采用Xml方式展示所有的Ribbon菜单基本控件************************/
            Mg.Get <IMgRibbon>().InsertRibbonTab(this, new RibbonTypeTabViewModel(), 2);
            //插入返回页的项
            Mg.Get <IMgRibbon>().InsertBackstageItem(this, new RibbonBackstageItemViewModel
            {
                Header       = "新添加的项",
                Content      = new FirstViewModel(),
                IsSelectable = true,
            });
            await Task.Yield();
        }
Beispiel #7
0
 public void Install(IPluginInfo pluginInfo)
 {
     _groupVm = M.RibbonManager.GetRibbonGroup("BasicViewGroup");//获取视图菜单中的基本菜单组
     if (_groupVm != null)
     {
         _viewBtn = new RibbonButtonViewModel
         {
             Text  = "弹出HelloWorld窗口",
             Click = new RelayCommand(ShowWindow) //按钮命令
         };
         _groupVm.Items.Add(_viewBtn);            //在基本菜单组里添加一个按钮
     }
     else
     {
         this.ShowMessage("没有找到名称为ViewGroup的RibbonGroup!插件无法插入相关Ribbon菜单!");
     }
 }
        /// <summary>
        /// Add a button to the ribbon
        /// </summary>
        /// <param name="tab">Tab header</param>
        /// <param name="tabId">Tab id</param>
        /// <param name="group">Group header</param>
        /// <param name="button">Button</param>
        public void AddRibbonButton(string tab, string tabId, string group, RibbonButtonViewModel button)
        {
            if (!_tabs.Any(x => x.Header == tab))
            {
                _tabs.Add(new RibbonTabViewModel(tab, tabId));
            }

            RibbonTabViewModel tabvm = _tabs.First(x => x.Header == tab);

            if (!tabvm.Groups.Any(x => x.Header == group))
            {
                tabvm.Groups.Add(new RibbonGroupViewModel(group));
            }

            RibbonGroupViewModel groupVM = tabvm.Groups.First(x => x.Header == group);

            groupVM.Buttons.Add(button);
        }