コード例 #1
0
        public Editor Set(Control edit)
        {
            _editor = edit;
            if (_editor is TextBox)
            {
                (_editor as TextBox).LostFocus += (sender, args) => SwapToOriginal();

                _editor.KeyUp += (sender, args) =>
                {
                    if (args.Key == Key.Enter)
                    {
                        SwapToOriginal();
                    }
                };
            }
            if (_editor is ComboBox)
            {
                //(_editor as ComboBox).LostFocus += (sender, args) => SwapToOriginal();
                _editor.CastTo <ComboBox>().DropDownOpened += (sender, args) =>
                {
                    _comboBoxOpened = true;
                };
                (_editor as ComboBox).SelectionChanged += (sender, args) =>
                {
                    if (_editorIsShown && _comboBoxOpened)
                    {
                        SwapToOriginal();
                    }
                };
            }

            // Don't swap to original on checkboxes, just show the editor
            if (_editor is CheckBox)
            {
                var bind = _source.GetDefaultBind();
                _editor.SetDefaultBind(bind);
                _swap(_source, _editor, null);
                _editorIsShown = true;
            }
            return(this);
        }