Example #1
0
        /// <summary>
        ///     Called when a cell has just switched to edit mode.
        /// </summary>
        /// <param name="editingElement">A reference to element returned by GenerateEditingElement.</param>
        /// <param name="editingEventArgs">The event args of the input event that caused the cell to go into edit mode. May be null.</param>
        /// <returns>The unedited value of the cell.</returns>
        protected override object PrepareCellForEdit(FrameworkElement editingElement, RoutedEventArgs editingEventArgs)
        {
            DatePicker textBox = editingElement as DatePicker;

            if (textBox != null)
            {
                textBox.Focus();

                string originalValue = textBox.Text;

                //TextCompositionEventArgs textArgs = editingEventArgs as TextCompositionEventArgs;
                //if (textArgs != null)
                //{
                //    // If text input started the edit, then replace the text with what was typed.
                //    string inputText = textArgs.Text;
                //    textBox.Text = inputText;

                //    // Place the caret after the end of the text.
                //    textBox.Select(inputText.Length, 0);
                //}
                //else
                //{
                //    // If a mouse click started the edit, then place the caret under the mouse.
                //    MouseButtonEventArgs mouseArgs = editingEventArgs as MouseButtonEventArgs;
                //    if ((mouseArgs == null) || !PlaceCaretOnTextBox(textBox, Mouse.GetPosition(textBox)))
                //    {
                //        // If the mouse isn't over the textbox or something else started the edit, then select the text.
                //        textBox.SelectAll();
                //    }
                //}

                return(originalValue);
            }

            return(null);
        }