WPF TextBox에 숫자만 입력받고자 한다. 여러가지 방법이 있겠지만 PreviewTextInput event를
이용하여 간단히 해결 한다. 
코드는 char.IsDigit가 조건에 맞을 경우 e.Handled = true; 로 적용하여 event가 적용될 수 있도록 한다.
private void OnValue_PreviewTextInput(object sender, TextCompositionEventArgs e)
{
    if ((e.Text) == null || !(e.Text).All(char.IsDigit))
    {
        e.Handled = true;
    }
}
'개발언어 > .NET' 카테고리의 다른 글
| Regex(정규식)을 이용한 IP주소 확인 (0) | 2021.01.29 | 
|---|---|
| Windows Keyboard 이벤트 (0) | 2021.01.22 | 
| WPF Window this.Close() 동작 (0) | 2020.12.19 | 
| C# 폴더에 특정 확장자 파일 검색, 파일 확장자 변경 (0) | 2020.09.26 | 
| Windows10 시작프로그램 삭제 (0) | 2020.08.08 |