private void RibbonControl_Loaded(object sender, RoutedEventArgs e) { var ribbonWindow = (RibbonWindow)sender; var ribbon = ribbonWindow.FindAllChildrenOfType <Microsoft.Windows.Controls.Ribbon.Ribbon>().Where(a => a.Name == "ribbon").FirstOrDefault(); if (ribbon == null) { return; } var dataContext = ribbon.DataContext; if (dataContext is IRibbonMainWindowViewModel) { IRibbon windowsRibbon = (dataContext as IRibbonMainWindowViewModel).WindowRibbon; var quickAccessMenus = windowsRibbon.QuickAccessMenuItems; if (quickAccessMenus != null && quickAccessMenus.Count > 0) { ribbon.QuickAccessToolBar = new RibbonQuickAccessToolBar(); foreach (var quickMenu in windowsRibbon.QuickAccessMenuItems) { var ribbonButton = new RibbonButton(); ribbonButton.Command = quickMenu.Command; ribbonButton.Label = quickMenu.Header; if (!string.IsNullOrEmpty(quickMenu.ImageUri)) { ribbonButton.SmallImageSource = new BitmapImage(new Uri(quickMenu.ImageUri)); } ribbon.QuickAccessToolBar.Items.Add(ribbonButton); } } } }
private void RibbonControl_Closing(object sender, System.ComponentModel.CancelEventArgs e) { var ribbonWindow = (RibbonWindow)sender; var ribbon = ribbonWindow.FindAllChildrenOfType <Microsoft.Windows.Controls.Ribbon.Ribbon>().Where(a => a.Name == "ribbon").FirstOrDefault(); if (ribbon == null) { return; } var dataContext = ribbon.DataContext; if (dataContext is IRibbonMainWindowViewModel) { IRibbon windowsRibbon = (dataContext as IRibbonMainWindowViewModel).WindowRibbon; windowsRibbon.QuickAccessMenuItems.Clear(); if (ribbon.QuickAccessToolBar != null && ribbon.QuickAccessToolBar.Items != null && ribbon.QuickAccessToolBar.Items.Count > 0) { foreach (var item in ribbon.QuickAccessToolBar.Items) { if (item is RibbonButton) { var ribbonItem = item as RibbonButton; windowsRibbon.QuickAccessMenuItems.Add (new Gno.Framework.ClientShell.Ribbon.MenuItem(ribbonItem.Label, ribbonItem.SmallImageSource == null ? string.Empty : ribbonItem.SmallImageSource.ToString(), ribbonItem.Command)); } } } } }
public CustomUi() { ElementName = "customUI"; privateNamespaces = new Dictionary <string, string>(); Ribbon = new Ribbon.Ribbon(); }
public CustomUi(string defaultNamespace) : base("customUI") { _defaultNamespace = defaultNamespace; _privateNamespaces = new Dictionary <string, string>(); Ribbon = new Ribbon.Ribbon(); }
public CustomUi() { ElementName = "customUI"; privateNamespaces = new Dictionary<string, string>(); Ribbon = new Ribbon.Ribbon(); }
public AddIn(InteropApplication application, IProgram program, IRibbon ribbon) { this.Application = application; this.Program = program; this.Ribbon = ribbon; this.workbookByInteropWorkbook = new Dictionary <InteropWorkbook, Workbook>(); ((InteropAppEvents_Event)this.Application).NewWorkbook += async interopWorkbook => { if (!string.IsNullOrWhiteSpace(this.ExistentialAttribute)) { var customProperties = new CustomProperties(interopWorkbook.CustomDocumentProperties); if (!customProperties.Exist(this.ExistentialAttribute)) { return; } } var workbook = this.New(interopWorkbook); for (var i = 1; i <= interopWorkbook.Worksheets.Count; i++) { var interopWorksheet = (InteropWorksheet)interopWorkbook.Worksheets[i]; workbook.New(interopWorksheet); } var worksheets = workbook.Worksheets; await this.Program.OnNew(workbook); foreach (var worksheet in worksheets) { await program.OnNew(worksheet); } }; this.Application.WorkbookOpen += async interopWorkbook => { if (!string.IsNullOrWhiteSpace(this.ExistentialAttribute)) { var customProperties = new CustomProperties(interopWorkbook.CustomDocumentProperties); if (!customProperties.Exist(this.ExistentialAttribute)) { return; } } var workbook = this.New(interopWorkbook); for (var i = 1; i <= interopWorkbook.Worksheets.Count; i++) { var interopWorksheet = (InteropWorksheet)interopWorkbook.Worksheets[i]; workbook.New(interopWorksheet); } var worksheets = workbook.Worksheets; await this.Program.OnNew(workbook); foreach (var worksheet in worksheets) { await program.OnNew(worksheet); } }; this.Application.WorkbookActivate += interopWorkbook => { if (!string.IsNullOrWhiteSpace(this.ExistentialAttribute)) { var customProperties = new CustomProperties(interopWorkbook.CustomDocumentProperties); if (!customProperties.Exist(this.ExistentialAttribute)) { return; } } if (!this.WorkbookByInteropWorkbook.TryGetValue(interopWorkbook, out var workbook)) { workbook = this.New(interopWorkbook); } workbook.IsActive = true; }; this.Application.WorkbookDeactivate += wb => { // Could already be gone by the WorkbookBeforeClose event if (this.WorkbookByInteropWorkbook.TryGetValue(wb, out _)) { this.WorkbookByInteropWorkbook[wb].IsActive = false; } }; void WorkbookBeforeClose(InteropWorkbook interopWorkbook, ref bool cancel) { if (this.WorkbookByInteropWorkbook.TryGetValue(interopWorkbook, out var workbook)) { this.Program.OnClose(workbook, ref cancel); if (!cancel) { this.Close(interopWorkbook); } } } this.Application.WorkbookBeforeClose += WorkbookBeforeClose; }