Or do you want something like the following?
Xaml:
<TextBox x:Name="tb2" Width="200" Height="105" PreviewTextInput="txt_PreviewTextInput"/>
Codebehind:
private void txt_PreviewTextInput(object sender, TextCompositionEventArgs e)
{
foreach (char ch in e.Text)
if (!(Char.IsDigit(ch) || ch.Equals('.')))
{
e.Handled = true;
}
}
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our [documentation][5] to enable e-mail notifications if you want to receive the related email notification for this thread.
[5]: https://learn.microsoft.com/en-us/answers/articles/67444/email-notifications.html