UIElement.OpacityMask Property

Gets or sets the brush used to alter the opacity of regions of this object.

Namespace:  System.Windows
Assembly:  System.Windows (in System.Windows.dll)

Syntax

'Declaration
Public Property OpacityMask As Brush
public Brush OpacityMask { get; set; }
<uiElement>
  <uiElement.OpacityMask>
    singleBrush
  </uiElement.OpacityMask>
</uiElement>

XAML Values

Property Value

Type: System.Windows.Media.Brush
A brush that describes the opacity applied to this object. The default is nulla null reference (Nothing in Visual Basic).

Remarks

Dependency property identifier field: OpacityMaskProperty

This property only uses the alpha channel values from the supplied Brush. The other channels of the brush content (Red, Green, or Blue) are ignored.

The most typical Brush for this purpose is an ImageBrush, which can be used for a variety of masking techniques such as a vignette, using an irregular shape. Technically, any defined Brush (such as LinearGradientBrush) can be used. VideoBrush is not recommended for this purpose, because videos generally do not carry alpha information (also, the codecs used by Silverlight cannot process alpha information in video). A SolidColorBrush created with one of the construction syntaxes that specifies an alpha in ARGB form is permitted, but the results would be indistinguishable from using an Opacity that used the same factor as the alpha for the SolidColorBrush.

Generally the XAML syntax for these brushes requires a Brush-derived object element to fill property element syntax in XAML, so this is the XAML syntax shown above. An attribute syntax that involves a SolidColorBrush and its string conversion behavior is technically possible; however, SolidColorBrush is not typically used for OpacityMask, for the reasons discussed in the previous remark.

Examples

The following XAML example places a centered elliptical mask on an image, such that the image fades out to zero opacity at the ellipse edges using a radial gradient.

<Image Source="sampleImages/forest.jpg" Height="100">
  <Image.OpacityMask>
    <RadialGradientBrush Center="50,50" GradientOrigin="50,50" MappingMode="Absolute" RadiusX="90" RadiusY="50">
      <GradientStop Color="#00000000" Offset="25" />
      <GradientStop Color="#20000000" Offset="12" />
      <GradientStop Color="#FF000000" Offset="0" />
    </RadialGradientBrush>
  </Image.OpacityMask>
</Image> 

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.