1234567891011121314151617181920212223242526272829303132333435 |
- using Avalonia.Controls;
- using Avalonia.Input;
- using Avalonia.Interactivity;
- using InABox.Core;
- 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 DoubleBox : NumericUpDown
- {
- protected override Type StyleKeyOverride => typeof(NumericUpDown);
- public DoubleBox()
- {
- ParsingNumberStyle = NumberStyles.Number;
- ShowButtonSpinner = false;
- AddHandler(TextInputEvent, TunnelTextEvent, RoutingStrategies.Direct | RoutingStrategies.Tunnel);
- }
- private void TunnelTextEvent(object? sender, TextInputEventArgs e)
- {
- e.Text = new string(e.Text?.WithIndex()
- .Where(x => (x.Key == 0 && x.Value == '-') || Char.IsDigit(x.Value) || x.Value == '.')
- .Select(x => x.Value).ToArray());
- if(e.Text == "")
- {
- e.Handled = true;
- }
- }
- }
|