GradientBrush.MappingMode Property

Gets or sets a BrushMappingMode enumeration that specifies whether the gradient brush's positioning coordinates are absolute or relative to the output area.

Namespace:  System.Windows.Media
Assembly:  PresentationCore (in PresentationCore.dll)
XMLNS for XAML: http://schemas.microsoft.com/winfx/2006/xaml/presentation, http://schemas.microsoft.com/netfx/2007/xaml/presentation

member MappingMode : BrushMappingMode with get, set
<object MappingMode="BrushMappingMode" .../>

Property Value

Type: System.Windows.Media.BrushMappingMode
A BrushMappingMode value that specifies how the gradient brush's positioning coordinates are interpreted. The default is BrushMappingMode.RelativeToBoundingBox.

Identifier field

MappingModeProperty

Metadata properties set to true

None

A value of Absolute indicates the gradient brush's coordinates are expressed using device independent pixels.

The following example shows how to use the MappingMode property to specify what coordinate system to use for the StartPoint and EndPoint of the gradient.

<Page 
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  <StackPanel>

    <!-- Both of the rectangles below have identical gradients applied but use different
         coordinate systems to specify the StartPoint and EndPoint of the gradient. -->
    <Rectangle Width="200" Height="100" Margin="10">
      <Rectangle.Fill>

        <!-- The MappingMode property is set to "Absolute" which specifies that the coordinate 
             system used for the StartPoint and EndPoint properties is not relative to the 
             Brush output area. Values are interpreted directly in local space (in pixels). -->
        <LinearGradientBrush MappingMode="Absolute" 
            StartPoint="0,50" EndPoint="200,50">
          <GradientStop Color="Yellow" Offset="0" />
          <GradientStop Color="Red" Offset="0.25" />
          <GradientStop Color="Blue" Offset="0.75" />
          <GradientStop Color="LimeGreen" Offset="1" />
        </LinearGradientBrush>
      </Rectangle.Fill>
    </Rectangle>

    <Rectangle Width="200" Height="100" Margin="10">
      <Rectangle.Fill>

        <!-- The MappingMode property is set to "RelativeToBoundingBox" (default) which  
             specifies the coordinate system for the StartPoint and EndPoint are relative to 
             the Brush output area: 0 indicates 0 percent of the output area and 1 indicates 
             100 percent of the output area.  -->
        <LinearGradientBrush StartPoint="0,0.5" EndPoint="1,0.5">
          <GradientStop Color="Yellow" Offset="0" />
          <GradientStop Color="Red" Offset="0.25" />
          <GradientStop Color="Blue" Offset="0.75" />
          <GradientStop Color="LimeGreen" Offset="1" />
        </LinearGradientBrush>
      </Rectangle.Fill>
    </Rectangle>

  </StackPanel>
</Page>

.NET Framework

Supported in: 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft