Skip to content

WritingXamlMappings

ldfallas edited this page Sep 11, 2015 · 4 revisions

Windows Phone 8.0 Silverilght uses XAML to describe pages and user controls. These XAML files have references to controls and code tied to the Windows Phone platform.

The UWP conversion tool provides a mechanism for creating mappings of Xaml code. These mappings are stored in '.xmap' files . The following code shows an example of a Xaml mapping file:

   <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="WebBrowser"
                              ElementNamespace="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone">
         <xmap:XamlElementMapper.Maps>
            <xmap:XamlMap Kind="Element">
               <xmap:XamlMap.Action>
                  <xmap:RenameElement NewName="WebView"
                                      NewNamespace="http://schemas.microsoft.com/winfx/2006/xaml/presentation" />
               </xmap:XamlMap.Action>
            </xmap:XamlMap>
            <xmap:XamlMap Kind="Property" PropertyName="Navigating">
               <xmap:XamlMap.Action>
                  <xmap:ActionSequence>
                     <xmap:ChangeEventHandlerEventArgsType
                                    NewEventArgsTypeName="Windows.UI.Xaml.Controls.WebViewNavigationStartingEventArgs" />
                     <xmap:RenameProperty NewPropertyLocalName="NavigationStarting" />
                  </xmap:ActionSequence>
               </xmap:XamlMap.Action>
            </xmap:XamlMap>
         </xmap:XamlElementMapper.Maps>
         <xmap:XamlElementMapper.ReferencedPackages>
            <x:String>CommonEventsToChange</x:String>
         </xmap:XamlElementMapper.ReferencedPackages>
      </xmap:XamlElementMapper>
   </MapUnit.Elements>
</MapUnit>

The previous mapping definition shows the definition of a MapUnit that contains a mapping for the WebBrowser control .

MapUnit

A "Map unit" is a container of mappings for Windows Phone Xaml elements.

An empty "Map unit" 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>
      ...
   </MapUnit.Elements>
</MapUnit>

xmap:XamlElementMapper

The XamlElementMapper element defines mappings for a XAML element. An empty mapper for the WebBrowser control (https://msdn.microsoft.com/en-us/library/windows/apps/microsoft.phone.controls.webbrowser%28v=vs.105%29.aspx) looks like this:

...
<xmap:XamlElementMapper ElementName="WebBrowser"
                        ElementNamespace="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone">
   <xmap:XamlElementMapper.Maps>
      ...
   </xmap:XamlElementMapper.Maps>
</xmap:XamlElementMapper>
...

Mappings

Inside XamlElementMapper we can define mappings for the current element . For example the equivalent control to WebBrowser is the WebView control (https://msdn.microsoft.com/library/windows/apps/windows.ui.xaml.controls.webview.aspx) . We can write a mapping for the element name as follows:

<xmap:XamlMap Kind="Element">
  <xmap:XamlMap.Action>
     <xmap:RenameElement NewName="WebView" NewNamespace="http://schemas.microsoft.com/winfx/2006/xaml/presentation" />
  </xmap:XamlMap.Action>
</xmap:XamlMap>

Mappings are used to apply mapping actions for example in this case use used the RenameElement Xaml Mapping Action.

Overview

Writing mappings

Code Mapping Actions

Code Mapping Conditions

XAML mapping actions

XAML mapping conditions

Misc

Clone this wiki locally