Skip to content

CommentOutElement Xaml Mapping Action

ldfallas edited this page Aug 31, 2015 · 3 revisions

Description

Comments out the current XAML element.

Properties

No properties

Example

We want to comment out Setter instances that have references to a Windows Phone static resource.

For example:

--Windows Phone 8 Silverlight--

...
<Style TargetType="TextBlock">
    <Setter Property="Foreground" Value="{StaticResource PhoneAccentBrush}"/>
</Style>
...

The mapping definition 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>
        <xmap:XamlElementMapper ElementName="Setter" ElementNamespace="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
            <xmap:XamlElementMapper.Maps>
                <xmap:XamlMap Kind="Element">
                    <xmap:XamlMap.Action>
                        <xmap:CommentOutElement>
                            <xmap:CommentOutElement.Condition>
                                <xmap:ElementContainsAttribute PropertyLocalName="Value" PropertyValueRegex="^.StaticResource Phone.*" />
                            </xmap:CommentOutElement.Condition>
                        </xmap:CommentOutElement>
                    </xmap:XamlMap.Action>
                </xmap:XamlMap>
            </xmap:XamlElementMapper.Maps>
        </xmap:XamlElementMapper>
    </MapUnit.Elements>
</MapUnit>

The converted code looks like this:

<Style TargetType="TextBlock">
  <!--<Setter Property="Foreground" Value="{StaticResource PhoneAccentBrush}" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" />-->
</Style>

Notes

  • This XAML action only applies to elements. If this action is applied to a property no action will be performed

Overview

Writing mappings

Code Mapping Actions

Code Mapping Conditions

XAML mapping actions

XAML mapping conditions

Misc

Clone this wiki locally