Opacity Masks WPF in VB.NET

In this article you will learn about the opacity masks in the WPF.
  • 2273

Opacity Mask: OpacityMask property is used to make specific regions of an element transparent or partially transparent. It's name implies a mask which is given to the visibility of a visual element.So the places which are not covered by the mask will be transparent.
The OpacityMask property accepts any brush. The alpha channel of the brush determines where the transparency occurs. For example, if you use a SolidColorBrush that's set to a transparent color for your OpacityMask, your entire element will disappear. If you use a SolidColorBrush that's set to use a nontransparent color, your element will remain completely visible.
The main application of OpacityMask is to define some transparent areas in visual elements.Let's consider the example below.

Example of the Opacity Mask

<Window x:Class="Window1"
    Title="Window1" Height="300" Width="300">
    <Grid x:Name="Opacity">
    <Rectangle Fill="Blue" />
    <Ellipse Stroke="Gainsboro">
            <LinearGradientBrush EndPoint="0.10,.70" StartPoint="0.600,0.500">
                <GradientStop Color="#FF000011" Offset="0.400"/>
                <GradientStop Color="#11FFFFFF" Offset="0.500"/>
            <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                <GradientStop Color="#11111111" Offset="0.54"/>
                <GradientStop Color="#FFFF00" Offset="0.4"/>

In above example I have used a LinearGradientBrush with Brush transform to implement this.When we are specifying OpacityMask,it won't consider the color of the brush.

Output Window



Hope this article helps you understand all about the opacity masks in the WPF.


More Articles

© 2020 DotNetHeaven. All rights reserved.