20240815_FJEQ_upperpc_seabed/FujianEarthquake_seabed_UI/FujianEarthquake/Views/SystemControlView.xaml.cs

74 lines
2.0 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace FujianEarthquake.Views
{
/// <summary>
/// SystemControlView.xaml 的交互逻辑
/// </summary>
public partial class SystemControlView : UserControl
{
public SystemControlView()
{
InitializeComponent();
this.DataContext = MainWindow.mainViewModel;
}
private void SetVoltageTB_PreviewTextInput(object sender, TextCompositionEventArgs e)
{
//e.Handled = !IsTextValidForIntegerOrDecimal(e.Text);
string input = e.Text;
if (!char.IsDigit(input[0]) && input != "." && !char.IsControl(input[0]))
{
e.Handled = true;
}
}
private void SetCurrentTB_PreviewTextInput(object sender, TextCompositionEventArgs e)
{
e.Handled = !IsTextValidForIntegerOrDecimal(e.Text);
}
private void ProVoltageTB_PreviewTextInput(object sender, TextCompositionEventArgs e)
{
e.Handled = !IsTextValidForIntegerOrDecimal(e.Text);
}
private void ProCurrentTB_PreviewTextInput(object sender, TextCompositionEventArgs e)
{
e.Handled = !IsTextValidForIntegerOrDecimal(e.Text);
}
private bool IsTextValidForIntegerOrDecimal(string text)
{
if (string.IsNullOrEmpty(text))
return false;
foreach (char c in text)
{
if (char.IsControl(c) || c == '.')
continue;
if (!char.IsDigit(c))
return false;
}
return true;
}
}
}