Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Event Handler located in different class than MainWindow

So I followed the guide on the following site to restrict the characters a textbox can accept.

http://www.rhyous.com/2010/06/18/how-to-limit-or-prevent-characters-in-a-textbox-in-csharp/

My problem is I can't figure out how to make the event handler trigger in the secondary class. Basically how do I tell VS to look for the event handler code in that class instead of MainWindow? I tried searching, but apparently don't know the correct terms to use. The xaml reference I used was

xmlns:DigitBox="clr-namespace:System.Windows.Controls;assembly=PresentationFramework"

Any ideas?

like image 551
Keven M Avatar asked Oct 09 '22 13:10

Keven M


1 Answers

Simplest way I've found to do it is assign the event in your constructor.

public MainWindow()
    {
        InitializeComponent();
        TextBoxCurrency.GotFocus += expandedTextBoxEvents.TextBoxCurrencyGotFocus;
        TextBoxCurrency.LostFocus += expandedTextBoxEvents.TextBoxCurrencyLostFocus;
    }

I've searched a way to do it in XAML and I did not found an easy and clean way to do it.

like image 169
Guish Avatar answered Oct 18 '22 07:10

Guish