37 lines
No EOL
1.1 KiB
C#
37 lines
No EOL
1.1 KiB
C#
using System.Globalization;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Input;
|
|
using ActiproSoftware.Windows.Controls.Editors;
|
|
|
|
namespace JD.PropertyEditor.Editors
|
|
{
|
|
public class CustomSingleEditBox : SingleEditBox
|
|
{
|
|
public CustomSingleEditBox()
|
|
{
|
|
Loaded += OnLoaded;
|
|
}
|
|
|
|
private void OnLoaded(object sender, RoutedEventArgs e)
|
|
{
|
|
if (Template.FindName("PART_TextBox", this) is TextBox textBox)
|
|
{
|
|
textBox.PreviewKeyDown += TextBoxOnPreviewKeyDown;
|
|
}
|
|
}
|
|
|
|
private void TextBoxOnPreviewKeyDown(object sender, KeyEventArgs e)
|
|
{
|
|
if (e.Key == Key.Decimal)
|
|
{
|
|
TextBox txb = sender as TextBox;
|
|
int caretPos = txb.CaretIndex;
|
|
txb.Text = txb.Text.Insert(txb.CaretIndex,
|
|
CultureInfo.CurrentCulture.NumberFormat.CurrencyDecimalSeparator);
|
|
txb.CaretIndex = caretPos + 1;
|
|
e.Handled = true;
|
|
}
|
|
}
|
|
}
|
|
} |