public CaseDesigner() { this.InitializeComponent(); this.DragHandle = null; this.Loaded += (sender, e) => { Selection selection = this.Context.Items.GetValue <Selection>(); if (selection != null) { ModelItem primarySelection = selection.PrimarySelection; this.ExpandState = SwitchDesigner.IsDescendantOfCase(this.ModelItem, primarySelection); if (this.ExpandState) { // If current focus is at another part, we need to focus this designer // to trigger selection changed, then this part will expand and another // expanded part will collapse. Then we focus on the activity it contains // if there is one. this.ModelItem.Highlight(); if (this.ModelItem != primarySelection && primarySelection.View != null) { primarySelection.Highlight(); } } } }; }
void OnModelItemPropertyChanged(object sender, PropertyChangedEventArgs e) { if (e.PropertyName == "Expression") { Update(); } else if (e.PropertyName == "DefaultCaseDisplayName") { // To fix 218600 without losing PropertyGrid focus (Bug 210326), the only workaround is to // update the connector label manually, because FlowSwitchLink.ModelItem["DefaultCaseDisplayName"] // is a FakeModelPropertyImpl, and would not generate a Undo unit // (FakeModelNotifyPropertyChange.GetInverse() returns null). // However, there is a known issue with PropertyGrid bound to a fake ModelItem. The workaround is // to shift the focus to the FlowchartDesigner IF the keyboard focus is on the connector when the user // calls Undo/Redo, to avoid the problem of PropertyGrid not refreshable. FlowchartDesigner flowchartDesigner = VisualTreeUtils.FindVisualAncestor <FlowchartDesigner>(this); Fx.Assert(null != flowchartDesigner, "flowchart designer cannot be null because FlowswitchDesigner must exist within the same visual tree ofthe parent Flowchart."); if (null != flowchartDesigner && null != this.ModelItem.Properties["Default"].Value && this.Context.Services.GetService <UndoEngine>().IsUndoRedoInProgress) { // the designer is available Connector connector = flowchartDesigner.GetLinkOnCanvas(this.ModelItem, this.ModelItem.Properties["Default"].Value, "Default"); Fx.Assert(null != connector, "Connector should not be null."); ModelItem linkModelItem = FlowchartDesigner.GetLinkModelItem(connector); Fx.Assert(linkModelItem is FakeModelItemImpl, "ModelItem of FlowSwitch link is fake."); IFlowSwitchDefaultLink link = (IFlowSwitchDefaultLink)linkModelItem.GetCurrentValue(); string defaultDisplayName = (string)this.ModelItem.Properties[FlowSwitchLabelFeature.DefaultCaseDisplayNamePropertyName].Value.GetCurrentValue(); if (link.DefaultCaseDisplayName != defaultDisplayName) { // the purpose of re-setting the link value during Undo/Redo is to update the FlowSwitch label using (ModelEditingScope scope = this.ModelItem.BeginEdit(SR.FlowSwitchDefaultCaseDisplayNameEditingScopeDesc)) { linkModelItem.Properties[FlowSwitchLabelFeature.DefaultCaseDisplayNamePropertyName].SetValue(defaultDisplayName); link.DefaultCaseDisplayName = defaultDisplayName; scope.Complete(); } if (Selection.IsSelection(linkModelItem)) { // cause the connector to lose focus, because the PropertyGrid would not have focus. // this scenario only happens if the user explicitly selects the FlowSwitch link after // editing the DefaultDisplayName. This behavior is only a workaround due to the fact // that PropertyGrid does not receive update from change in a FakeModelPropertyImpl // (i.e. FlowSwitchLink). Keyboard.ClearFocus(); Selection.SelectOnly(this.Context, this.ModelItem); linkModelItem.Highlight(); } } } } }
private void HighlightModelItemOnDesigner(ModelItem selectedModelItem) { if (selectedModelItem != null) { Selection.SelectOnly(this.ParentTreeView.Context, selectedModelItem); // Set highlight to visual value. // Don't use "Focus()" since it will steal keyboard focus and disable // keyboard navigation. selectedModelItem.Highlight(); } }