private void OnAboutActionExecuted(object sender, MenuActionEventArgs e) { var dialog = new AboutUI(); dialog.WindowStartupLocation = WindowStartupLocation.CenterScreen; dialog.Topmost = true; dialog.ShowDialog(); }
/// <summary> /// Update the state of the menu items. /// If the Selected Item is a TabControl, a TabItem or /// the contents of a TabItem, then make the menu item visible. /// </summary> /// <param name="sender">Event sender.</param> /// <param name="e">Event argument.</param> private void TabControlContextMenuProvider_UpdateItemStatus(object sender, MenuActionEventArgs e) { // Update AddTab visibility. if (e.Selection.SelectionCount == 1) { ModelItem primarySelection = e.Selection.PrimarySelection; if (primarySelection.IsItemOfType(MyPlatformTypes.TabItem.TypeId)) { // ensure the TabItem is parented to a TabControl. ModelItem parent = primarySelection.Parent; _addTabMenuAction.Visible = (parent != null && parent.IsItemOfType(MyPlatformTypes.TabControl.TypeId)); } else if (primarySelection.IsItemOfType(MyPlatformTypes.TabControl.TypeId)) { _addTabMenuAction.Visible = true; } else { // if it's the TabItem.Content, treat it as the TabItem ModelItem directParent = primarySelection.Parent; if (directParent != null && directParent.IsItemOfType(MyPlatformTypes.TabItem.TypeId)) { ModelItem tabControl = (directParent != null) ? directParent.Parent : null; _addTabMenuAction.Visible = (tabControl != null && tabControl.IsItemOfType(MyPlatformTypes.TabControl.TypeId)); } } } else { _addTabMenuAction.Visible = false; } }
// The following method handles the Execute event. // It sets the Background property to Brushes.Blue. void SetBackgroundToBlue_Execute( object sender, MenuActionEventArgs e) { ModelItem selectedControl = e.Selection.PrimarySelection; selectedControl.Properties["Background"].SetValue(Brushes.Blue); }
// The following method handles the Execute event. // It sets the Background property to its default value. void ClearBackground_Execute( object sender, MenuActionEventArgs e) { ModelItem selectedControl = e.Selection.PrimarySelection; selectedControl.Properties["Background"].ClearValue(); }
private void OnInsertPage(object sender, MenuActionEventArgs e) { ModelItem wizard = GetWizard(e.Selection.PrimarySelection); if (wizard != null) { DesignerOperations.InsertPage(wizard); } }
/// <summary> /// Remove columns /// </summary> private void RemoveColumnsMenuAction_Execute(object sender, MenuActionEventArgs e) { ModelItem selectedDataGrid = e.Selection.PrimarySelection; using (ModelEditingScope scope = selectedDataGrid.BeginEdit("Delete Grid Columns")) { selectedDataGrid.Properties["Columns"].Collection.Clear(); scope.Complete(); } }
/// <summary> /// Update the state of the menu items based on the state of the model /// </summary> private void DataGridMenuProvider_UpdateItemStatus(object sender, MenuActionEventArgs e) { ModelItem selectedDataGrid = e.Selection.PrimarySelection; object dataSource = selectedDataGrid.Properties[PlatformTypes.DataGrid.ItemsSourceProperty].ComputedValue; if (dataSource == null) { editPropertyBoundColumnsMenuAction.Enabled = false; } else { editPropertyBoundColumnsMenuAction.Enabled = true; } }
// The following method handles the Execute event. // It adds reference using modified AssemblyReferences APIs. void AddReference_Execute( object sender, MenuActionEventArgs e) { ModelItem selectedControl = e.Selection.PrimarySelection; List <AssemblyIdentifier> assemblies = new List <AssemblyIdentifier>(); assemblies.Add(new AssemblyIdentifier("AddReferenceDemo", "..\\CustomControlLibrary.WpfCore\\bin\\Debug\\netcoreapp3.0\\AddReferenceDemo.dll")); AssemblyReferences assemblyReferences = new AssemblyReferences(assemblies); selectedControl.Context.Items.SetValue(assemblyReferences); }
/// <summary> /// Add and configure Columns /// </summary> private void AddColumnsMenuAction_Execute(object sender, MenuActionEventArgs e) { using (ModelEditingScope scope = e.Selection.PrimarySelection.BeginEdit("Columns Changed")) { AddDataGridColumnsUserInterface ui = new AddDataGridColumnsUserInterface(e.Context, e.Selection.PrimarySelection); // Use Windows Forms to show the design time because Windows Forms knows about the VS message pump System.Windows.Forms.DialogResult result = DesignerDialog.ShowDesignerDialog("Add/Edit Columns", ui); if (result == System.Windows.Forms.DialogResult.OK) { scope.Complete(); } else { scope.Revert(); } } }
/// <summary> /// Add Columns using DisplayMemberBinding /// </summary> private void GenerateStockColumnsMenuAction_Execute(object sender, MenuActionEventArgs e) { AddColumns(e.Selection.PrimarySelection, e.Context); }
/// <summary> /// Update the state of the menu items based on the state of the model /// </summary> private void DataGridMenuProvider_UpdateItemStatus(object sender, MenuActionEventArgs e) { ModelItem selectedDataGrid = e.Selection.PrimarySelection; object dataSource = selectedDataGrid.Properties[ItemsControl.ItemsSourceProperty].ComputedValue; if (dataSource == null) { isDatasourceSetMenuAction.DisplayName = "You need to set ItemsSource to enable some column operations."; isDatasourceSetMenuAction.Visible = true; generateStockColumnsMenuAction.Visible = false; } else { isDatasourceSetMenuAction.DisplayName = string.Empty; isDatasourceSetMenuAction.Visible = false; generateStockColumnsMenuAction.Visible = true; } if (selectedDataGrid.Properties["Columns"].Collection.Count < 1) { removeColumnsMenuAction.Visible = false; } else { removeColumnsMenuAction.Visible = true; } }
/// <summary> /// Add and configure Columns /// </summary> private void EditPropertyBoundColumnsMenuAction_Execute(object sender, MenuActionEventArgs e) { DataGridActions.EditPropertyBoundColumns(e.Selection.PrimarySelection, e.Context); }
/// <summary> /// Remove columns /// </summary> private void RemoveColumnsMenuAction_Execute(object sender, MenuActionEventArgs e) { DataGridActions.RemoveColumns(e.Selection.PrimarySelection, e.Context); }
/// <summary> /// AddTab menu item action. /// </summary> /// <param name="sender">Event sender.</param> /// <param name="e">Event arguments.</param> private void AddTabMenuAction_Execute(object sender, MenuActionEventArgs e) { ModelItem primarySelection = e.Selection.PrimarySelection; ModelItem tabControl = null; if (primarySelection.IsItemOfType(MyPlatformTypes.TabControl.TypeId)) { tabControl = e.Selection.PrimarySelection; } else if (primarySelection.IsItemOfType(MyPlatformTypes.TabItem.TypeId)) { ModelItem parent = e.Selection.PrimarySelection.Parent; if (parent != null && parent.IsItemOfType(MyPlatformTypes.TabControl.TypeId)) { tabControl = parent; } } if (tabControl != null) { using (ModelEditingScope changes = tabControl.BeginEdit(Properties.Resources.TabControl_AddTabMenuItem)) { ModelItem newTabItem = ModelFactory.CreateItem(e.Context, MyPlatformTypes.TabItem.TypeId, CreateOptions.InitializeDefaults); tabControl.Content.Collection.Add(newTabItem); // change selection to newly created TabItem. Selection sel = new Selection(newTabItem); e.Context.Items.SetValue(sel); changes.Complete(); } } }
private void Action1_Execute(object sender, MenuActionEventArgs e) { MessageBox.Show("TestControlContextMenuProvider_UpdateItemStatus!"); }
private void RedBackground_Execute(object sender, MenuActionEventArgs e) { var item = e.Selection.PrimarySelection; item.Properties["Background"].SetValue(System.Windows.Media.Brushes.Red); }