-
Notifications
You must be signed in to change notification settings - Fork 5
ElementContainsAttribute Xaml Mapping Condition
ldfallas edited this page Aug 31, 2015
·
3 revisions
Verifies that the current element contains the specified element and that its value matches with the specified regular expression.
Property | Usage | Description |
---|---|---|
PropertyLocalName | Required | The local name of the property to be verified |
PropertyValueRegex | Required | A regular expression to check the value of the property |
We want to comment out Setter instances that have references to a Windows Phone static resource.
For example:
--Windows Phone 8 Silverlight--
...
<Style TargetType="TextBlock">
<Setter Property="Foreground" Value="{StaticResource PhoneAccentBrush}"/>
</Style>
...
The mapping definition looks like this:
<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="Setter" ElementNamespace="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<xmap:XamlElementMapper.Maps>
<xmap:XamlMap Kind="Element">
<xmap:XamlMap.Action>
<xmap:CommentOutElement>
<xmap:CommentOutElement.Condition>
<xmap:ElementContainsAttribute PropertyLocalName="Value" PropertyValueRegex="^.StaticResource Phone.*" />
</xmap:CommentOutElement.Condition>
</xmap:CommentOutElement>
</xmap:XamlMap.Action>
</xmap:XamlMap>
</xmap:XamlElementMapper.Maps>
</xmap:XamlElementMapper>
</MapUnit.Elements>
</MapUnit>
The converted code looks like this:
<Style TargetType="TextBlock">
<!--<Setter Property="Foreground" Value="{StaticResource PhoneAccentBrush}" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" />-->
</Style>
Here we used the ElementContainsAttribute
condition to determine if we will comment out the current XAML element.
- The regular expression is a common .NET regular expression.
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