Skip to content

ChangeEventHandlerEventArgsType Xaml Mapping Action

ldfallas edited this page Aug 17, 2015 · 2 revisions

Description

This action is used assuming that the current property refers to an event handler.

The action will change the C# code behind by replacing the type of the second argument of the event handler. This argument is commonly known as the "event argument".

Properties

Property ​Usage ​Description
​NewEventArgsTypeName ​Required The name of the type to be used as the type of the second argument of the event handler.

Examples

One example where changing the type of the event arguments object is required is the conversion from UIElement.Tap event to UIElement.Tapped .

For example given the following code:

--Windows Phone Silverlight 8 XAML--

...
<Button Tap="MyHandler"/>
...

The code behind could look like this:

--Windows Phone Silverlight 8 C#--

...
void MyHandler(object sender, GestureEventArgs args)
{
  ...
}
...

We can write the mapping using the ChangeEventHandlerEventArgsType code action as follows:

<xmap:XamlMap Kind="Property" PropertyName="Tap">
  <xmap:XamlMap.Action>
    <xmap:ActionSequence>
      <xmap:ChangeEventHandlerEventArgsType NewEventArgsTypeName="Windows.UI.Xaml.Input.TappedRoutedEventArgs" />
      <xmap:RenameProperty NewPropertyLocalName="Tapped" />
    </xmap:ActionSequence>
  </xmap:XamlMap.Action>
</xmap:XamlMap>

Applying the mapping above will generate the following code:

--Windows UWP XAML--

...
<Button Tapped="MyHandler"/>
...

The code behind could look like this:

--Windows UWP C#--

...
void MyHandler(object sender, Windows.UI.Xaml.Input.TappedRoutedEventArgs args)
{
  ...
}
...

Notes

  1. The value of the 'NewEventArgsTypeName' attribute must be a valid C# type name.
  2. If the value of the ​'NewEventArgsTypeName' has generic parameters then the following must be considered
    • If the property is specified using the attribute syntax the &gt; and &lt; entities must be used. For example: NewEventArgsTypeName="MyTypes&lt;T&gt;" .
    • If the property is specified using the element syntax, a CDATA section can be used to specify the value. For example:
<xmap:ChangeEventHandlerEventArgsType>
   <xmap:ChangeEventHandlerEventArgsType.NewEventArgsTypeName>
      <![CDATA[MyType<T>]]>
   </xmap:ChangeEventHandlerEventArgsType.NewEventArgsTypeName>
</xmap:ChangeEventHandlerEventArgsType>

Overview

Writing mappings

Code Mapping Actions

Code Mapping Conditions

XAML mapping actions

XAML mapping conditions

Misc

Clone this wiki locally