-
Notifications
You must be signed in to change notification settings - Fork 5
AddParentElementResource Xaml Mapping Action
ldfallas edited this page Aug 31, 2015
·
1 revision
<map:AddParentElementResource>
<AddParentElementResource.ReplacementTemplateContents>
...XAML TEMPLATE...
</AddParentElementResource.ReplacementTemplateContents>
</map:AddParentElementResource>
This XAML mapping action allows adding a resource to the top level element (a Page or UserControl) by using a XAML template.
Property | Usage | Description |
---|---|---|
ReplacementTemplateContents | Content property | A XAML template with the value of the new resource being generated |
NewResourceNameTemplateVariable | Optional | The name of a template variable that can be used to refer to the generated resource key |
The following example shows how to use this action to extract the value of the Text
property from TextBlocks
and put them in a resource.
<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='Element'>
<xmap:ActionSequence>
<xmap:BindPropertyValueElement ContextKeyName='$txt' PropertyName='Text'/>
<xmap:AddParentElementResource NewResourceNameTemplateVariable='$resKey'>
<![CDATA[ <x:String xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'> The text: $txt </x:String> ]]>
</xmap:AddParentElementResource>
<xmap:SetPropertyValueToSimpleValue AttributeToChangeName='Text' NewPropertyValue='{}{StaticResource $resKey}'/>
</xmap:ActionSequence>
</xmap:XamlMap>
</xmap:XamlElementMapper.Maps>
</xmap:XamlElementMapper>
</MapUnit.Elements>
</MapUnit>
By applying this mapping to this source code:
--Windows Phone 8 Silverlight --
<phone:PhoneApplicationPage ... >
...
<StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
<TextBlock Text="MY APPLICATION" Style="{StaticResource PhoneTextNormalStyle}" Margin="12,0"/>
<TextBlock Text="page name" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
</StackPanel>
...
</Grid>
</phone:PhoneApplicationPage>
We get the following code:
--Windows UWP--
<Page ...>
<Page.Resources>
<x:String xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" x:Key="newResourceResource"> The text: MY APPLICATION </x:String>
<x:String xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" x:Key="newResourceResource0"> The text: page name </x:String>
</Page.Resources>
...
<StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
<TextBlock Margin="12,0" Text="{StaticResource newResourceResource}" />
<TextBlock Margin="9,-7,0,0" Text="{StaticResource newResourceResource0}" />
</StackPanel>
...
</Page>
- The value of the
ReplacementTemplateContents
must be a valid XAML string
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