private void DefaultBeginContentEdit(DObject obj) { if (m_EditingLabel) return; FrameworkElement fe = ContentEditorProvider.GetNewGUIInstance(obj); if (fe != null) { DecorateObjectForDragging(obj); m_LabelEditor = new LabelEditor() { EditControl = fe, EditTarget = obj, HorizontalAlignment = HorizontalAlignment.Left, VerticalAlignment = VerticalAlignment.Top }; m_LabelEditor.Closed += (sender, args) => { RemoveObjDraggingDecorations(obj); if (m_LabelEditor.OK) ContentEditorProvider.UpdateLabel(fe, obj); m_EditingLabel = false; LayoutRoot.Children.Remove(m_LabelEditor); m_LabelEditor = null; }; m_EditingLabel = true; LayoutRoot.Children.Add(m_LabelEditor); SynchronizationContext.Current.Post(o => ContentEditorProvider.FocusGUI(fe, obj), null); } }
private void DefaultBeginContentEdit(DObject obj) { if (m_EditingLabel) return; DTextLabel clicked = obj is IHavingDLabel ? (obj as IHavingDLabel).Label as DTextLabel : obj as DTextLabel; DObject labelOwner = obj is DTextLabel ? (obj as DTextLabel).ParentObject : obj; if (clicked != null /*&& clicked != m_EditingLabel*/) { //EndContentEdit(); DTextLabel editingLabel = clicked; FrameworkElement fe = null; bool isMine = false; if (GetNewEditControlDelegate != null) fe = GetNewEditControlDelegate(labelOwner); else { isMine = true; fe = new TextBox() { MinWidth = 50.0, Text = editingLabel.Text, SelectionStart = 0, SelectionLength = editingLabel.Text.Length, AcceptsReturn = true }; } if (fe != null) { DecorateObjectForDragging(obj); m_LabelEditor = new LabelEditor() { EditControl = fe, EditTarget = obj, HorizontalAlignment = HorizontalAlignment.Left, VerticalAlignment = VerticalAlignment.Top }; if (isMine) { fe.KeyDown += (sender, args) => { if (System.Windows.Input.Keyboard.Modifiers == System.Windows.Input.ModifierKeys.None) { if (args.Key == System.Windows.Input.Key.Enter) m_LabelEditor.Close(true); else if (args.Key == System.Windows.Input.Key.Escape) m_LabelEditor.Close(false); } }; } m_LabelEditor.Closed += (sender, args) => { RemoveObjDraggingDecorations(obj); if (m_LabelEditor.OK) { if (GetTextFromEditControlDelegate != null) editingLabel.Text = GetTextFromEditControlDelegate(labelOwner, fe); else editingLabel.Text = (fe as TextBox).Text; BuildBBHierarchy(); } m_EditingLabel = false; LayoutRoot.Children.Remove(m_LabelEditor); m_LabelEditor = null; }; m_EditingLabel = true; LayoutRoot.Children.Add(m_LabelEditor); if (isMine) (fe as TextBox).Focus(); } } }