Gets or sets the brush used to alter the opacity of regions of this object.
Assembly: System.Windows (in System.Windows.dll)
<uiElement> <uiElement.OpacityMask> singleBrush </uiElement.OpacityMask> </uiElement>
Property ValueType: System.Windows.Media.Brush
A brush that describes the opacity applied to this object. The default is null.
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 , for the reasons discussed in the previous remark.
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>
For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.