Alessandro Del Sole's Blog

{ A programming space about Microsoft® .NET® }
posts - 1909, comments - 2047, trackbacks - 352

My Links


Your host

This is me! Questo spazio è dedicato a Microsoft® .NET®, di cui sono molto appassionato :-)

Cookie e Privacy

Microsoft MVP

My MVP Profile

Microsoft Certified Professional

Microsoft Specialist

Xamarin Certified Mobile Developer

Il mio libro su VB 2015!

Pre-ordina il mio libro su VB 2015 Pre-ordina il mio libro "Visual Basic 2015 Unleashed". Clicca sulla copertina per informazioni!

Il mio libro su WPF 4.5.1!

Clicca sulla copertina per informazioni! E' uscito il mio libro "Programmare con WPF 4.5.1". Clicca sulla copertina per informazioni!

These postings are provided 'AS IS' for entertainment purposes only with absolutely no warranty expressed or implied and confer no rights.
If you're not an Italian user, please visit my English blog

Le vostre visite

I'm a VB!

Guarda la mia intervista a Seattle

Follow me on Twitter!

Altri spazi

I miei progetti open-source su GitHub

Article Categories


Post Categories

Image Galleries

Privacy Policy

OpacityMask 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: 

As you can see, along the button appear some transparency areas (which are drawn by a Transparent color). This could be a nice effect in imaging apps.


Print | posted on domenica 14 ottobre 2007 15:42 |

Powered by:
Powered By Subtext Powered By ASP.NET