SIGN UP MEMBER LOGIN:    
ARTICLE

Transparent Brushes in WPF

Posted by Mahesh Chand Articles | WPF with C# February 21, 2010
All elements in XAML including all brushes have an Opacity attribute that defines the transparency of an element. This article demonstrates how to use Opacity to implement transparent brushes in WPF using XAML.
Reader Level:

Transparent Brushes

All elements in XAML including all brushes have an Opacity attribute that defines the transparency of an element. The value of Opacity is between 0 and 1. The value 0 means an element is fully-transparent and value 1 means an element is fully opaque. The default value of Opacity is 1.

The following code snippet creates a SolidColorBrush with 50% transparency. You can set the Opacity attribute of any brush using same code.

<SolidColorBrush Color="Blue" Opacity="0.5"/>    

 

Now if we set Opacity of code in 25 as following, the output that looks like Figure 33 will look like Figure 34.

 

<VisualBrush Viewport="0,0,0.25, 0.25" TileMode="Tile" Opacity="0.5">

 

The following code snippet sets the Opacity property of a VisualBrush at run-time.

 

VisualBrush vBrush = new VisualBrush();

vBrush.Opacity = 0.50;

 tb.jpg


Figure 34. A rectangle with a transparent Visual brush in Tile mode


Transparent Controls

Good part is, this Opacity property not only is available for brushes but also for all elements in WPF and XAML. That means, you can create transparent Windows, Pages, Controls, or User Controls by simply setting this property.



Login to add your contents and source code to this article
share this article :
post comment
 
Become a Sponsor
PREMIUM SPONSORS
  • ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications. Visit DynamicPDF here
    Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites - Click Here!
Team Foundation Server Hosting
Become a Sponsor