Jak mogę sobie zbindować, zdarzenia dla danego textboxa. Bo w xamlu
PreviewTextInput="{Binding TextValidate}"
Tak to nie działa i się już z tym męczę dłuższy czas. Próbowałem też przez konstruktor przekazać Textboxa
public LibraryViewModel(TextBox tb)
{
tb = new TextBox();
YearBox = new TextBox();
YearBox = tb;
SetValidation();
_business = new Business();
BooksCollection = new ObservableCollection<Book>(_business.GetBooks());
RentCollection = new ObservableCollection<Rent>(_business.GetRents());
}
i potem wywoałać w nim funkcję
private void SetValidation()
{
this.YearBox.PreviewTextInput += (sender, args) =>
{
var regex = new Regex("[^0-9]+");
args.Handled = regex.IsMatch(args.Text);
OnPropertyChanged();
};
}
ale tak też nie przeszło