Opacity Masks in WPF / Silverlight

Discovered the opacitymask property today! If you want to be able to apply a gradient brush to an object in one direction, but change the opacity in another (think blending out objects horizontally against a background with a gradient running vertically) then you can do it like this…


<Rectangle>
<Rectangle.OpacityMask>
<LinearGradientBrush EndPoint="0.0,0.5" StartPoint="1,0.5">
<GradientStop Color="#FF000000" Offset="0"/>
<GradientStop Color="#00FFFFFF" Offset="1"/>
</LinearGradientBrush>
</Rectangle.OpacityMask>
<Rectangle.Fill>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FF03D3E0"/>
<GradientStop Color="#FF006A74" Offset="1"/>
</LinearGradientBrush>
</Rectangle.Fill>
</Rectangle>
This entry was posted in Uncategorized. Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>