Skip to content

SetPropertyValueToComplexElement Xaml Mapping Action

ldfallas edited this page Aug 31, 2015 · 3 revisions

Description

This action is used to set the value of an element to a complex value.

Complex value means that the property is specified using XAML.

Properties

Property ​Usage ​Description
​TemplateContents Content property / Required The template for the generated Xaml property value

Examples

We want to convert the Microsoft.Phone.Shell.ApplicationBarIconButton.IconUri to a element-style property that contains a BitmapIcon element.

<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="ApplicationBarIconButton" 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:XamlMap Kind="Property" PropertyName="IconUri" >
                    <xmap:XamlMap.Action>
                        <xmap:ActionSequence>
                            <xmap:BindPropertyValueElement ContextKeyName="$URI" />
                            <xmap:SetPropertyValueToComplexElement >
                                <xmap:SetPropertyValueToComplexElement.TemplateContents>
                                    <![CDATA[
                                            <BitmapIcon UriSource="$URI" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"/>
                                    ]]>
                                </xmap:SetPropertyValueToComplexElement.TemplateContents>
                            </xmap:SetPropertyValueToComplexElement>
                        </xmap:ActionSequence>
                    </xmap:XamlMap.Action>
                </xmap:XamlMap>
                ....
        </xmap:XamlElementMapper>
    </MapUnit.Elements>
</MapUnit>

Here the $URI is being bound to the current value of the IconUri property.

For example the following code

-- Windows Phone 8 Silverlight --

    <phone:PhoneApplicationPage.ApplicationBar>
        <shell:ApplicationBar>
            <shell:ApplicationBarIconButton IconUri="/Assets/Save.png" Text="xaa"/>
        </shell:ApplicationBar>
    </phone:PhoneApplicationPage.ApplicationBar>

Is converted to the following UWP code:

-- UWP --

  <Page.BottomAppBar>
    <CommandBar>
      <AppBarButton Label="xaa">
        <AppBarButton.Icon>
          <BitmapIcon UriSource="/Assets/Save.png" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" />
        </AppBarButton.Icon>
      </AppBarButton>
    </CommandBar>
  </Page.BottomAppBar>

Notes

  • The contents of the property must be valid XAML. It is recommended to use a CDATA section to specify the value of this property.
  • Variables must be referenced as a dollar sign '$' and a sequence of letters. For example $letter
  • Template variables can only appear in:
    • attribute bodies
    • element bodies
  • A template must be valid XML
  • This action is commonly used in conjunction with the [BindPropertyValueElement Xaml mapping action](BindPropertyValueElement Xaml mapping action) which is used to bind variables

Overview

Writing mappings

Code Mapping Actions

Code Mapping Conditions

XAML mapping actions

XAML mapping conditions

Misc

Clone this wiki locally