-
Notifications
You must be signed in to change notification settings - Fork 5
ReplaceEventHandlerBodyWithTemplate Xaml Mapping Action
ldfallas edited this page Aug 31, 2015
·
3 revisions
Replaces the content of an event handler with the evaluation of a C# code template.
Property | Usage | Description |
---|---|---|
CodeTemplate | Content property / Required | The C# code template |
The following mapping will add an if
statement that wraps the method body with a condition regarding its first parameter.
<MapUnit xmlns='clr-namespace:Mobilize.Mappers.Extensibility.Core;assembly=Mobilize.ExtensibleMappers'
xmlns:xmap='clr-namespace:Mobilize.XamlMappers;assembly=Mobilize.XamlMapper'
xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' >
<MapUnit.Elements>
<xmap:XamlElementMapper ElementName="TextBlock" ElementNamespace="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<xmap:XamlElementMapper.Maps>
<xmap:XamlMap Kind="Property" PropertyName="Tap">
<xmap:XamlMap.Action>
<xmap:ActionSequence>
<xmap:ChangeEventHandlerEventArgsType
NewEventArgsTypeName="Windows.UI.Xaml.Input.TappedRoutedEventArgs" />
<xmap:ReplaceEventHandlerBodyWithTemplate >
<![CDATA[ if($parameter1Name != null) $body; ]]>
</xmap:ReplaceEventHandlerBodyWithTemplate>
<xmap:RenameProperty NewPropertyLocalName="Tapped" />
</xmap:ActionSequence>
</xmap:XamlMap.Action>
</xmap:XamlMap>
</xmap:XamlElementMapper.Maps>
</xmap:XamlElementMapper>
</MapUnit.Elements>
</MapUnit>
Say that we have the following code:
--XAML (Windows Phone Silverlight)--
<TextBlock x:Name="someText" Tap="TextBlock_Tap">Some text</TextBlock>
--C#(Windows Phone Silverlight)--
private void TextBlock_Tap(object sender, System.Windows.Input.GestureEventArgs e)
{
MessageBox.Show("Hello!");
}
After running the conversion tool with this new mapping we get the following code:
--XAML (UWP)--
<TextBlock x:Name="someText" Tapped="TextBlock_Tap">Some text</TextBlock>
--C# (UWP)--
private async void TextBlock_Tap(object sender, Windows.UI.Xaml.Input.TappedRoutedEventArgs e)
{
if ( e != null )
{
await (new Windows.UI.Popups.MessageDialog("Hello!")).ShowAsync();
}
}
Variable name | Description |
---|---|
$parameter0Name, $parameter1Name, ..., $parameterXName | The names of the parameters of the current method. Parameter names are 0 based. |
$body | The block with the body of the current method |
TODO
Contact us for more information
Overview
Writing mappings
Code Mapping Actions
- ActionSequence
- AddHelper
- AddNamespaceImport
- AddPreStatementFromTemplate
- CommentOut
- Conditional
- Keep Code Mapping Action
- MarkAsNotMapped
- RedirectCall
- RedirectCallToInnerMember
- RedirectIndexer
- RedirectProperty
- RemoveCurrentStatement
- RemoveParameter
- ReplaceClassUsage
- ReplaceMethodBodyWithTemplate
- ReplaceParameterDeclarationType
- ReplaceParameterMember
- ReplaceParameterValue
- ReplaceWithMethodCall
- ReplaceWithProperty
- ReplaceWithTemplate
Code Mapping Conditions
- AllConditionsApply
- ArgumentCount
- AssignName
- AssignNameToArgumentRange
- IsExpressionOfType
- IsStringLiteralMatchingRegex
- WithArgument
- WithAssignment
- WithAssignmentLeftSide
- WithAssignmentRightSide
- WithCalledMemberOwner
- WithCalledMethodExpression
- WithConstructorCall
- WithLambdaExpressionBody
- WithLambdaExpressionParameter
- WithLeftSideOfDottedAccess
- WithMemberInitValue
- WithMethodCall
XAML mapping actions
- ActionSequence
- AddStatementToConstructorFromTemplate
- BindPropertyValueElement Xaml mapping action
- ChangeEventHandlerEventArgsType
- CommentOutElement
- CommentOutProperty
- MarkAsNotMapped
- MoveValueToContentProperty
- RemoveNamespaceDeclaration
- RenameElement
- RenameProperty
- ReplaceAttributeValue
- ReplaceEventHandlerBodyWithTemplate
- ReplaceEventHandlerParameterMember
- ReplaceNamespaceDeclaration
- ReplacePropertyValueWithParentResource
- ReplaceStaticResourceWithThemeResource
- SetPropertyValueToComplexElement
- SetPropertyValueToSimpleValue
- WrapContent
XAML mapping conditions
Misc