Alessandro Del Sole's Blog

/* A programming space about Microsoft® .NET® */
posts - 159, comments - 0, trackbacks - 0

My Links


Your host

This is me! This space is about Microsoft® .NET® and Microsoft® Visual Basic development. Enjoy! :-)

These postings are provided 'AS IS' for entertainment purposes only with absolutely no warranty expressed or implied and confer no rights.

Microsoft MVP

My MVP Profile

I'm a VB!

Watch my interview in Seattle

My new book on VB 2015!

Pre-order VB 2015 Unleashed Pre-order my new book "Visual Basic 2015 Unleashed". Click for more info!

My new book on LightSwitch!

Visual Studio LightSwitch Unleashed My book "Visual Studio LightSwitch Unleashed" is available. Click the cover!

Your visits

Follow me on Twitter!

CodePlex download Download my open-source projects from CodePlex!

Article Categories


Post Categories

.NET Framework


Help Authoring

Microsoft & MSDN

Setup & Deployment

Visual Basic 2005/2008/2010

Opacity Mask in WPF

In Windows Presentation Foundation, the most of controls expose a property called OpacityMask which allows to create transparency areas along the object itself and diffuse those areas in different manners.

Let's see a practical sample on a Button. Start Visual Studio 2005 and create a new empty WPF project, then type the following XAML from within the Grid:

      <Button Width="220" Height="75">


          <LinearGradientBrush >

            <GradientStop Color="Transparent" Offset="0"/>

            <GradientStop Color="Black" Offset="0.5"/>

            <GradientStop Color="Transparent" Offset="1"/>



        This is a button with OpacityMask


We can use Brush objects to apply a gradient transparency to the control. In the above code I inserted just three GradientStop, but if you want to see how transparencies change you can add some more. Moreover you could set StartPoint and EndPoint attributes to the LinearGradientBrush, modifying the starting and ending gradient points. Anyway the above code snippet is a good starting point to learn OpacityMask. This is the result it produces: 


Print | posted on martedì 14 aprile 2009 14:18 | Filed Under [ Windows Presentation Foundation ]


No comments posted yet.

Post Comment

Please add 7 and 8 and type the answer here:

Powered by:
Powered By Subtext Powered By ASP.NET