We pay for user submitted tutorials and articles that we publish. Anyone can send in a contributionLearn More
Yesterday I was trying to create a control with a partially transparent background,. I am writing this because what I thought was so straight forward, was not.
Here is a simple example:
When we run this example we will get the following:
As you can see, the button is hidden. If we were to add Opacity=”0.5″ to the border we will be able to see the button:
Looks exactly what we wanted no? NO! Lets add a rectangle to the border and see what happens. The code now looks like this:
And this is the outcome:
As you can see the Rectangle got Opacity=”0.5″ as well. You can try overriding it and specifying the Opacity property to be 1, but it wont help.
I then thought to my self how can I limit the opacity to the Border and the solution was to specify the opacity only on the Border Background color. All I had to do was create a StaticResource Brush and set it’s transparency. Now the code looks like this:
Notice that the Border’s opacity is not set. And the outcome is exactly what we (I) wanted:
Only the background is transparent. This works also for Silverlight
Tags :controlSee ThroughSemi TransparentTransparent Background
Copyright © 2012 Dev102.com
Breeze : Designed by Amit Raz and Nitzan Kupererd