views:

5278

answers:

3

I would like to use a transparent png file on a silverlight button. In addition I would like the button itself to be transparent so the background (behind the button) shows through. I find that if I set the opacity of the button it also affects the image. I don't want the entire image to be transparent - just the transparent parts of it as defined in the PNG.

Any ideas on how this can be accomplished?

+3  A: 

Silverlight supports png transparency. This works:

<UserControl x:Class="SilverlightApplication17.Page"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
Width="400" Height="300">
<Grid x:Name="LayoutRoot" Background="Green">
<Button Width="200" Height="200">
  <Button.Content>
    <Image Source="http://wildermuth.com/images/tx_head.png" />  
  </Button.Content>
</Button>

You should see the image is transparent to the back of the button. If you want the button transparent, then yuo need to create a button template that is clear. The link in texmex5's answer is a descent one.

Shawn Wildermuth
+1  A: 

From my subsequent investigations, it seems that not all transparent PNGs will work. They have to be alpha-based transparencies (as opposed to palette-based). They also have to be at least 16-bit images. The standard 8-bit does not work.

arch
A: 

Ho to write same in c# code ? And the image show with in a button but with white border. how to remove border ?

Arun