Silverlight: Transparent image on button

buttonimageopacitysilverlight

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?

Best Answer

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.