using System.Text.RegularExpressions; using System.Windows; using System.Windows.Controls; using System.Windows.Input; using Aitex.Core.UI.MVVM; namespace VirgoUI.Client.Models.Utility.EndPoint { /// /// EndPointView.xaml 的交互逻辑 /// public partial class EndPointView : UserControl { public EndPointView() { InitializeComponent(); } private void OnPreviewTextInput(object sender, TextCompositionEventArgs e) { e.Handled = !IsTextAllowed(e.Text); } private static bool IsTextAllowed(string text) { Regex regex = new Regex("[^0-9.]+"); //regex that matches disallowed text return !regex.IsMatch(text); } } }