private void InitContextMenuCommandBindings() { CommandBindings.AddRange( new[] { new CommandBinding(AddScalarPropertyCommand, delegate { var addScalarPropertyWindow = new AddScalarPropertyWindow { Owner = Application.Current.MainWindow }; switch (addScalarPropertyWindow.ShowDialog()) { case true: var uiScalarProperty = UIType.AddScalarProperty(addScalarPropertyWindow.PropertyName, addScalarPropertyWindow.PropertyType.Value); SizeChangedEventHandler actionToDoWhenNewItemAdded = null; actionToDoWhenNewItemAdded = delegate { propertiesListView.SelectedValue = uiScalarProperty; GetListViewItem(uiScalarProperty.BusinessInstance as ScalarProperty).Focus(); propertiesListView.SizeChanged -= actionToDoWhenNewItemAdded; }; propertiesListView.SizeChanged += actionToDoWhenNewItemAdded; break; } }, (sender, e) => e.CanExecute = ApplyNotVisibleIfMoreThanOneTypeSelected(ContextMenu.GetMenuItem(MENUITEM_ADD, MENUITEM_ADD_SCALAR_PROPERTY)) ), new CommandBinding(AddComplexPropertyCommand, delegate { var addComplexPropertyWindow = new AddComplexPropertyWindow(ComplexTypesAllowedForComplexProperty) { Owner = Application.Current.MainWindow, DataContext = UIType.View }; switch (addComplexPropertyWindow.ShowDialog()) { case true: var uiComplexType = addComplexPropertyWindow.PropertyType; var businessComplexType = uiComplexType.BusinessInstance; var uiComplexProperty = UIType.AddComplexProperty(addComplexPropertyWindow.PropertyName, businessComplexType); DrawComplexPropertyRelationAfterAddedComplexProperty(uiComplexType, uiComplexProperty); break; } }, (sender, e) => e.CanExecute = ApplyNotVisibleIfMoreThanOneTypeSelected(ContextMenu.GetMenuItem(MENUITEM_ADD, MENUITEM_ADD_COMPLEX_PROPERTY)) && ComplexTypesAllowedForComplexProperty.Any() ), new CommandBinding(RenameCommand, (sender, e) => Rename(e.OriginalSource), (sender, e) => { var renameMenuItem = ContextMenu.GetMenuItem(MENUITEM_RENAME); if (SetVisibility(renameMenuItem, () => ApplyNotVisibleIfMoreThanOneTypeSelected(renameMenuItem) && !_groupRightClick)) { e.CanExecute = (e.OriginalSource == this || propertiesListView.SelectedItems.Count == 1); } else { e.CanExecute = false; } } ), new CommandBinding(DeleteCommand, (sender, e) => Delete(e.OriginalSource), (sender, e) => { var deleteMenuItem = ContextMenu.GetMenuItem(MENUITEM_DELETE); if (SetVisibility(deleteMenuItem, () => AllowDelete(deleteMenuItem))) { e.CanExecute = true; } else { e.CanExecute = false; } } ), new CommandBinding(DesignerCanvas.RemoveFromDesignerCommand, delegate { Designer.RemoveFromDesigner(); }, (sender, e) => e.CanExecute = SetVisibility(ContextMenu.GetMenuItem(MENUITEM_REMOVE_FROM_DESIGNER), () => !PropertiesTreeViewFocused) ), new CommandBinding(CutCommand, delegate { CutSelectedProperties(); }, (sender, e) => e.CanExecute = ApplyCutCopyVisible(ContextMenu.GetMenuItem(MENUITEM_CUT)) ), new CommandBinding(CopyCommand, delegate { CopySelectedProperties(); }, (sender, e) => e.CanExecute = ApplyCutCopyVisible(ContextMenu.GetMenuItem(MENUITEM_COPY)) ), new CommandBinding(PasteCommand, delegate { PasteClipboardProperties(); }, (sender, e) => e.CanExecute = ApplyPasteVisible() && CanPaste() ), //new CommandBinding(PropertiesCommand, // delegate // { // var focusedObject = VisualTreeHelperUtil.GetFocusedElement(this); // if (VisualTreeHelperUtil.IsAscendant(propertiesListView, focusedObject)) // Designer.Container.ShowPropertiesTab((UIProperty)propertiesListView.SelectedItem); // else // Designer.Container.ShowPropertiesTab(UIType); // }, // (sender, e) => // { // var propertiesMenuItem = ContextMenu.GetMenuItem(MENUITEM_PROPERTIES); // if (SetVisibility(propertiesMenuItem, () => ApplyNotVisibleIfMoreThanOneTypeSelected(propertiesMenuItem) && !_groupRightClick && (!PropertiesTreeViewFocused || propertiesListView.SelectedItems.Count == 1))) // e.CanExecute = true; // else // e.CanExecute = false; // } //), new CommandBinding(MappingCommand, delegate { var focusedObject = VisualTreeHelperUtil.GetFocusedElement(this); Designer.Container.ShowMappingTab(UIType); }, (sender, e) => { var mappingMenuItem = ContextMenu.GetMenuItem(MENUITEM_MAPPING); if (SetVisibility(mappingMenuItem, () => ApplyNotVisibleIfMoreThanOneTypeSelected(mappingMenuItem) && !_groupRightClick && (!PropertiesTreeViewFocused || propertiesListView.SelectedItems.Count == 1))) { e.CanExecute = true; } else { e.CanExecute = false; } } ), new CommandBinding(ShowBaseTypeCommand, delegate { Designer.UITypeToAdd = Designer.EDMView.CSDL.EntityTypes[((EntityType)UIType.BusinessInstance).BaseType]; }, (sender, e) => { var showBaseMenuItem = ContextMenu.GetMenuItem(MENUITEM_SHOW_BASE_TYPE); var entityType = UIType.BusinessInstance as EntityType; if (SetVisibility(showBaseMenuItem, () => ApplyNotVisibleIfMoreThanOneTypeSelected(showBaseMenuItem) && !_groupRightClick && (!PropertiesTreeViewFocused || propertiesListView.SelectedItems.Count == 1) && entityType != null && entityType.BaseType != null)) { e.CanExecute = !Designer.DesignerView.ContainsEntityType(entityType.BaseType); } else { e.CanExecute = false; } } ), new CommandBinding(ShowRelatedTypeCommand, delegate { Designer.UITypeToAdd = ((UIRelatedProperty)propertiesListView.SelectedItem).RelatedType; }, (sender, e) => { var showRelatedTypeMenuItem = ContextMenu.GetMenuItem(MENUITEM_SHOW_RELATED_TYPE); if (SetVisibility(showRelatedTypeMenuItem, () => ApplyNotVisibleIfMoreThanOneTypeSelected(showRelatedTypeMenuItem) && propertiesListView.SelectedItems.Count == 1 && propertiesListView.SelectedItem is UIRelatedProperty && !_groupRightClick)) { e.CanExecute = !Designer.DesignerView.ContainsEntityType(((UIRelatedProperty)propertiesListView.SelectedItem).RelatedType); } else { e.CanExecute = false; } } ), new CommandBinding(ShowOtherTabsCommand, delegate { }, (sender, e) => { var showOtherTabsMenuItem = ContextMenu.GetMenuItem(MENUITEM_SHOW_OTHER_TABS); var designerViews = Designer.EDMView.DesignerViews.Except(new [] { Designer.DesignerView }).Where(dv => dv.TypeDesignersLocations.Any(tdl => tdl.UIType.BusinessInstance == UIType.BusinessInstance)); e.CanExecute = designerViews.Any(); if (e.CanExecute) { ShowDesignerCanvasPreviews(Designer.EDMView, UIType, showOtherTabsMenuItem, designerViews); } else { showOtherTabsMenuItem.Items.Clear(); } } ) //new CommandBinding(ShowOtherTabsItemCommand, (sender, e) => ((IEDMDesignerWindow)VisualTreeHelperUtil.GetControlAscendant<Window>(this)).CurrentDesignerView = (DesignerView)e.Parameter) } ); var uiEntityType = UIType as UIEntityType; if (uiEntityType == null) { MenuItem addNavigationPropertyMenuItem = ContextMenu.GetMenuItem(MENUITEM_ADD, MENUITEM_ADD_NAVIGATION_PROPERTY); if (addNavigationPropertyMenuItem != null) { addNavigationPropertyMenuItem.Visibility = Visibility.Collapsed; } } else { CommandBindings.Add(new CommandBinding(AddNavigationPropertyCommand, DesignerCanvas.AddAssociationExecuted(this, () => UIType.View, () => Designer.DesignerView, uiEntityType, (UIAssociation uiAssociation) => { if (uiAssociation.NavigationProperty1.ParentType == UIType) { propertiesListView.SelectedValue = uiAssociation.NavigationProperty1; GetListViewItem(uiAssociation.NavigationProperty1.BusinessInstance).Focus(); } } ), (sender, e) => e.CanExecute = ApplyNotVisibleIfMoreThanOneTypeSelected(ContextMenu.GetMenuItem(MENUITEM_ADD, MENUITEM_ADD_NAVIGATION_PROPERTY)) )); } ContextMenuOpening += (sender, e) => { if (MoreThanOneTypeSelected && (_groupRightClick || PropertiesTreeViewFocused)) { e.Handled = true; } ApplyNotVisibleIfMoreThanOneTypeSelected(ContextMenu.GetMenuItem(MENUITEM_ADD)); }; }