cetin
cetin

Reputation: 2055

Image button Transparency Problem in WPF

I want to apply transparency to a button which contains an image, but button's transparent seems when application start. How can ı do this?

<Button Grid.Column="1" Name="btnClose" 
                        BorderBrush="Transparent" 
                        Background="Transparent"
                        BorderThickness="0" Click="btnClose_Click">
                    <Image  Source="close.ico" ></Image>
</Button>

and what is the method that close the-

Upvotes: 1

Views: 2666

Answers (2)

brunnerh
brunnerh

Reputation: 185350

1 - To set the overall transparency of the button you should set the Opacity property to something between 0 and 1. Not sure what you want to do at application start but if you set values in XAML those are automatically applied at startup. If you want to animate it to become visible please clarify.

2 - To only show the image you can override the template of the button to only show its content, add this to the Button:

<Button.Template>
    <ControlTemplate>
        <ContentPresenter />
    </ControlTemplate>
</Button.Template>

3 - To exit the application when the button is clicked add this to the handler of the click event:

App.Current.Shutdown();

Upvotes: 2

ferhrosa
ferhrosa

Reputation: 1792

When I tested your code here the button was "shown" only when the cursor was over it.

Another way to do this is use only the Image control and it's MouseLeftButtonDown event.
Put the this.Close(); command in it and you have a image that closes the form when clicked.

Upvotes: 0

Related Questions