Alessandro Del Sole's Blog

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

My Links

News

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 2012

Order my book about VB 2012 on Amazon My book "Visual Basic 2012 Unleashed" is available. Click the cover!

My new book on LightSwitch!

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

Your visits

campusMVP.NET - Tutored online training for Microsoft developers

Follow me on Twitter!

Messenger me!


CyberInstaller Beta Tester

Download CIS 2008!!

CodePlex download Download my open-source projects from CodePlex!

Search the blog



Article Categories

Archives

Post Categories

.NET Framework

Blogroll

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">

        <Button.OpacityMask>

          <LinearGradientBrush >

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

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

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

          </LinearGradientBrush>

        </Button.OpacityMask>

        This is a button with OpacityMask

      </Button>

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: 

Alessandro

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

Feedback

No comments posted yet.

Post Comment

Title  
Name  
Email
Url
Comment   
Please add 4 and 7 and type the answer here:

Powered by:
Powered By Subtext Powered By ASP.NET