123456789101112131415161718192021222324252627282930313233 |
- using Avalonia.Controls;
- using Avalonia.Input;
- using Avalonia.Interactivity;
- using System;
- using System.Collections.Generic;
- using System.Globalization;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace InABox.Avalonia.Components;
- public class IntegerBox : NumericUpDown
- {
- protected override Type StyleKeyOverride => typeof(NumericUpDown);
- public IntegerBox()
- {
- ParsingNumberStyle = NumberStyles.Integer;
- FormatString = "N0";
- ShowButtonSpinner = false;
- AddHandler(TextInputEvent, TunnelTextEvent, RoutingStrategies.Direct | RoutingStrategies.Tunnel);
- }
- private void TunnelTextEvent(object? sender, TextInputEventArgs e)
- {
- e.Text = new string(e.Text?.Where(c => Char.IsDigit(c)).ToArray());
- if(e.Text == "")
- {
- e.Handled = true;
- }
- }
- }
|