Skip to content

Writing a mapping for event handlers

ldfallas edited this page Aug 17, 2015 · 2 revisions

With the change to UWP some event handlers need to be changed . For example:

...
<TextBlock Tap="TextBlock_Tap">Some text</TextBlock>
...

In this case the Windows Phone Silverlight's System.Windows.UIElement.Tap event (https://msdn.microsoft.com/en-us/library/system.windows.uielement.tap(v=vs.95).aspx) is being used. The event handler in this case looks like this:

private void TextBlock_Tap(object sender, System.Windows.Input.GestureEventArgs e)
{
   MessageBox.Show("Hello!");
}

In order to convert this code to UWP we need to change from the 'Tap' event to the Windows.UI.Xaml.UIElement.Tapped (https://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.uielement.tapped) event .

The target UWP code may look like this:

<TextBlock Tapped="TextBlock_Tap">Some text</TextBlock>

The event handler signature must also be changed. Here's the expected code:

private async void TextBlock_Tap(object sender, Windows.UI.Xaml.Input.TappedRoutedEventArgs e)
{
    await (new Windows.UI.Popups.MessageDialog("Hello!")).ShowAsync();
}

TODO

Overview

Writing mappings

Code Mapping Actions

Code Mapping Conditions

XAML mapping actions

XAML mapping conditions

Misc

Clone this wiki locally