Monday, October 14, 2013

How to Add Tapped Event to the Textbox in Windows 8 Application.

Over the forum discussion, some one asked an question “Tapped Event” is not occurring/firing in his application, so I have decided to write a quick code snippet for the same solution.

I did quick work around and added AddHandler() method. And it adds a routed event handler for a specified routed event.

See the following code snippet:

txtMyTextBox.AddHandler(TappedEvent, new TappedEventHandler(txtMyTextBox_Tapped), true);

void txtMyTextBox_Tapped(object sender, TappedRoutedEventArgs e)
            MessageDialog msgDialog = new MessageDialog("Tapped Event occour", "Windows 8 App");

            //OK Button
            UICommand okBtn = new UICommand("OK");
            okBtn.Invoked = OkBtnClick;

            //Cancel Button
            UICommand cancelBtn = new UICommand("Cancel");
            cancelBtn.Invoked = CancelBtnClick;

            //Show message

Here is a completed source code.

Hope it will help, Happy Coding.