예제 #1
0
        /// <summary>
        /// Method checks if pasted string contains input that is invalid and cancels
        /// past command if string is not conforming to regular expression.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private static void OnPaste(object sender, DataObjectPastingEventArgs e)
        {
            if (e.DataObject.GetDataPresent(DataFormats.Text))
            {
                var RegularExpression = AllowableCharactersTextBoxBehavior.GetRegularExpressionProperty(sender as TextBox);

                string text = System.Convert.ToString(e.DataObject.GetData(DataFormats.Text));

                if (!IsValid(text, true, RegularExpression))
                {
                    e.CancelCommand();
                }
            }
            else
            {
                e.CancelCommand();
            }
        }
예제 #2
0
        /// <summary>
        /// Previews a text change and cancels the change if text appears to be invalid.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private static void uiElement_PreviewTextInput(object sender, System.Windows.Input.TextCompositionEventArgs e)
        {
            var RegularExpression = AllowableCharactersTextBoxBehavior.GetRegularExpressionProperty(sender as TextBox);

            e.Handled = !IsValid(e.Text, false, RegularExpression);
        }