internal void RegisterAttachedProperty <T>(string propertyName, bool isBrowsable, bool isVisibleToModelItem, T defaultValue) { AttachedProperty <T> attachedProperty = new AttachedProperty <T> { IsBrowsable = isBrowsable, IsVisibleToModelItem = isVisibleToModelItem, Name = propertyName, OwnerType = modelType, Getter = (modelItem) => { T result = (T)viewStateService.RetrieveViewState(modelItem, propertyName); return(result == null ? defaultValue : result); }, Setter = (modelItem, value) => { if (value == null || value.Equals(defaultValue)) { viewStateService.StoreViewStateWithUndo(modelItem, propertyName, null); } else { viewStateService.StoreViewStateWithUndo(modelItem, propertyName, value); } } }; attachedPropertiesService.AddProperty(attachedProperty); attachedProperties.Add(propertyName, attachedProperty); }
void UpdateViewState(string oldValue, string newValue) { EditingContext context = this.flowSwitchModelItem.GetEditingContext(); ViewStateService viewStateService = (ViewStateService)context.Services.GetService(typeof(ViewStateService)); if (viewStateService != null) { object viewState = viewStateService.RetrieveViewState(this.flowSwitchModelItem, oldValue); if (viewState != null) { viewStateService.StoreViewStateWithUndo(this.flowSwitchModelItem, oldValue, null); viewStateService.StoreViewStateWithUndo(this.flowSwitchModelItem, newValue, viewState); } } }
protected override void OnPreviewMouseLeftButtonUp(MouseButtonEventArgs e) { if (e != null && !this.Disabled && this.scope != null) { ModelItem stateContainerModelItem = this.ParentStateContainerEditor.ModelItem; ViewStateService viewStateService = this.ParentStateContainerEditor.Context.Services.GetService <ViewStateService>(); viewStateService.StoreViewStateWithUndo(stateContainerModelItem, StateContainerEditor.StateContainerWidthViewStateKey, this.ParentStateContainerEditor.StateContainerWidth); viewStateService.StoreViewStateWithUndo(stateContainerModelItem, StateContainerEditor.StateContainerHeightViewStateKey, this.ParentStateContainerEditor.StateContainerHeight); Mouse.OverrideCursor = null; Mouse.Capture(null); StateMachineDesigner stateMachineDesigner = VisualTreeUtils.FindVisualAncestor <StateMachineDesigner>(this.ParentStateContainerEditor); stateMachineDesigner.IsResizing = false; e.Handled = true; } base.OnPreviewMouseLeftButtonUp(e); }
public static void OnAddAnnotationCommandExecuted(ExecutedRoutedEventArgs e, ModelItem modelItem) { ModelProperty property = modelItem.Properties.Find(Annotation.AnnotationTextPropertyName); if (property != null) { using (ModelEditingScope editingScope = modelItem.BeginEdit(SR.AddAnnotationDescription)) { property.SetValue(string.Empty); ViewStateService viewStateService = modelItem.GetEditingContext().Services.GetService <ViewStateService>(); viewStateService.StoreViewStateWithUndo(modelItem, Annotation.IsAnnotationDockedViewStateName, false); editingScope.Complete(); } if (modelItem.View != null) { WorkflowViewElement element = modelItem.View as WorkflowViewElement; if (element != null) { element.OnEditAnnotation(); } } } e.Handled = true; }
protected override void OnPreviewMouseLeftButtonUp(MouseButtonEventArgs e) { if (e != null && !this.Disabled) { ModelItem stateContainerModelItem = this.ParentStateContainerEditor.ModelItem; // Save the new size to view state. using (ModelEditingScope scope = stateContainerModelItem.BeginEdit(SR.Resize)) { ViewStateService viewStateService = this.ParentStateContainerEditor.Context.Services.GetService <ViewStateService>(); viewStateService.StoreViewStateWithUndo(stateContainerModelItem, StateContainerEditor.StateContainerWidthViewStateKey, this.ParentStateContainerEditor.StateContainerWidth); viewStateService.StoreViewStateWithUndo(stateContainerModelItem, StateContainerEditor.StateContainerHeightViewStateKey, this.ParentStateContainerEditor.StateContainerHeight); scope.Complete(); } Mouse.OverrideCursor = null; Mouse.Capture(null); e.Handled = true; } base.OnPreviewMouseLeftButtonUp(e); }
public static void OnDeleteAnnotationCommandExecuted(ExecutedRoutedEventArgs e, ModelItem modelItem) { using (ModelEditingScope editingScope = modelItem.BeginEdit(SR.DeleteAnnotationDescription)) { modelItem.Properties[Annotation.AnnotationTextPropertyName].SetValue(null); ViewStateService viewStateService = modelItem.GetEditingContext().Services.GetService <ViewStateService>(); viewStateService.StoreViewStateWithUndo(modelItem, Annotation.IsAnnotationDockedViewStateName, null); editingScope.Complete(); } e.Handled = true; }