Skip to content

ReplacePropertyValueWithParentResource Xaml Mapping Action

ldfallas edited this page Aug 31, 2015 · 3 revisions

Usage

<map:ReplacePropertyValueWithParentResource>
   <ReplacePropertyValueWithParentResource.ReplacementTemplateContents>
         ...XAML TEMPLATE...
   </ReplacePropertyValueWithParentResource.ReplacementTemplateContents>
</map:ReplacePropertyValueWithParentResource>

Description

This XAML mapping action replaces the value of the property with a static resource.

Properties

​Property ​Usage ​Description
ReplacementTemplateContents Content property A XAML template with the value of the new resource being generated

Example

Say for example that we want to move all the 'Content' properties of buttons to a static resource.

We can write the following mapping:

<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="Button" ElementNamespace="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
      <xmap:XamlElementMapper.Maps>
        ...
        <xmap:XamlMap Kind="Property" PropertyName="Content">
          <xmap:XamlMap.Action>
            <xmap:ActionSequence>
              <xmap:BindPropertyValueElement ContextKeyName="$CONTENT" />
              <xmap:ReplacePropertyValueWithParentResource  >
                <xmap:ReplacePropertyValueWithParentResource.ReplacementTemplateContents>
                  <![CDATA[<x:String xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'>$CONTENT</x:String>]]>
                </xmap:ReplacePropertyValueWithParentResource.ReplacementTemplateContents>
              </xmap:ReplacePropertyValueWithParentResource>
            </xmap:ActionSequence>
          </xmap:XamlMap.Action>
        </xmap:XamlMap>
        ...
      </xmap:XamlElementMapper.Maps>
      ...
    </xmap:XamlElementMapper>
  </MapUnit.Elements>
</MapUnit>

By applying this mapping to this source code:

--Windows Phone 8 Silverlight --

<Button Click="Button_Click" Content="Ok" ></Button>

We get the following code:

--Windows UWP--

<Page ...>
      <Page.Resources>
            <x:String xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" x:Key="ContentResource">Ok</x:String>
        </Page.Resources>
        <Button Click="Button_Click" Content="{Binding Source={StaticResource ContentResource }}"></Button>
</Page>

Notes

  • The value of the ReplacementTemplateContents must be a valid XAML string

Overview

Writing mappings

Code Mapping Actions

Code Mapping Conditions

XAML mapping actions

XAML mapping conditions

Misc

Clone this wiki locally