Skip to content

BindPropertyValueElement Xaml mapping action

ldfallas edited this page Aug 31, 2015 · 3 revisions

Description

This action is used to assign a variable to the value of the current property .

This XAML mapping action is commonly used in conjunction with the [SetPropertyValueToComplexElement Xaml Mapping Action](SetPropertyValueToComplexElement Xaml Mapping Action).

Properties

​Property ​Usage ​Description
ContextKeyName Required The name of the variable that is going to hold the value of the current property
PropertyName Optional The name of the attribute to get the value from
PropertyNamespace Optional Specifies (if required) the namespace of the property

Example

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 names of the variables must follow the same rules as the name of the C# code template variables. See the [AssignName Code Mapping Action](AssignName Code Mapping Action) for more details.

Overview

Writing mappings

Code Mapping Actions

Code Mapping Conditions

XAML mapping actions

XAML mapping conditions

Misc

Clone this wiki locally