Skip to content

RenameProperty Xaml Mapping Action

ldfallas edited this page Aug 17, 2015 · 2 revisions

Description

Renames a property of a Xaml element

Properties

​Property ​Usage ​Description
​NewPropertyLocalName ​Required ​The new name of the property
​​NewXmlNamespaceName ​Optional ​The new XML namespace of the property (may be used for attached properties)

Examples

Example #1

Say that we want to convert the 'Text' property of the 'ApplicationBarMenuItem' control to the 'Label' property of the 'AppBarButton' control on UWP.

<shell:ApplicationBar>
  <shell:ApplicationBar.MenuItems>
     <shell:ApplicationBarMenuItem Text="text for menu item 1"  />
     <shell:ApplicationBarMenuItem >
        <shell:ApplicationBarMenuItem.Text>
           Some other text for menu item 2
        </shell:ApplicationBarMenuItem.Text>
     </shell:ApplicationBarMenuItem>
  </shell:ApplicationBar.MenuItems>
</shell:ApplicationBar>

The mapper definition is the following:

<xmap:XamlElementMapper ElementName="ApplicationBarMenuItem" ElementNamespace="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone">
   <xmap:XamlElementMapper.Maps>
      <xmap:XamlMap Kind="Element">
         <xmap:XamlMap.Action>
            <xmap:RenameElement NewName="AppBarButton" NewNamespace="http://schemas.microsoft.com/winfx/2006/xaml/presentation" />
         </xmap:XamlMap.Action>
      </xmap:XamlMap>
      <xmap:XamlMap Kind="Property" PropertyName="Text" >
         <xmap:XamlMap.Action>
            <xmap:RenameProperty NewPropertyLocalName="Label" />
         </xmap:XamlMap.Action>
      </xmap:XamlMap>
   </xmap:XamlElementMapper.Maps>
   <xmap:XamlElementMapper.ReferencedPackages>
      <x:String>CommonEventsToChange</x:String>
   </xmap:XamlElementMapper.ReferencedPackages>
</xmap:XamlElementMapper>

By applying this mapping we get the following output

<CommandBar>
   <CommandBar.SecondaryCommands>
      <AppBarButton Label="text for menu item 1" />
      <AppBarButton>
         <AppBarButton.Label>
            Some other text for menu item 2
         </AppBarButton.Label>
      </AppBarButton>
   </CommandBar.SecondaryCommands>
</CommandBar>

Notes

This action can be used to rename both attribute and element properties (see the example above).

Overview

Writing mappings

Code Mapping Actions

Code Mapping Conditions

XAML mapping actions

XAML mapping conditions

Misc

Clone this wiki locally