I wanted to use your NumericTextBoxBehavior class with an editable combobox and I had to make some minor changes in the class in order for it to work.
I changed the OnEnableStateChanged method so it can handle more than just text boxes.
private static void OnEnabledStateChanged(DependencyObject sender,
UIElement tb = sender as UIElement;
if (tb == null || !(sender is ComboBox || sender is TextBox))
The first part of tbb_PreviewTextInput and OnClipboardPaste changes to:
static void tbb_PreviewTextInput(object sender, TextCompositionEventArgs e)
TextBox tb = getEditableTextBox(sender);
where getEditableTextBox looks like:
private static TextBox getEditableTextBox(object sender)
Control ctrl = sender as Control;
return ((sender is ComboBox) ? ctrl.Template.FindName("PART_EditableTextBox", ctrl) :
ctrl) as TextBox;
I also changed the regular expression so it could handle scientific notation:
string expr = @"^([-+]?)(\d*)([,.]?)(\d*)([eE]?)([+-]?)\d*$";
Maybe you want to implement it also. If not no problem.
Thanks for this great framework