Home > DeveloperSection > Forums > Convert image to a button WPF
Ankit Singh

Total Post:91

Points:117
Posted on    September-21-2013 6:42 AM

 WPF
Ratings:


 1 Reply(s)
 263  View(s)
Rate this:

I understand that i can overlay an image on a button, but is it possible that a button can take the exact size of an image? In other words, I want to get rid of the rectangular shaped button and adapt it to the size and shape of the image.



Sumit Kesarwani

Total Post:338

Points:2408
Posted on    September-21-2013 7:40 AM

Hi Ankit,

You can set the Template of button like below:

    <Button >

        <Image Source="pan-left.png"/>

        <Button.Template>

            <ControlTemplate TargetType="Button">

                <ContentPresenter Content="{TemplateBinding Content}"/>

            </ControlTemplate>

        </Button.Template>

    </Button>

TemplateBinding is used to set the Content property in order to set the Content inside the ControlTemplate, as you can move this ControlTemplate to the Resources and can use it for multiple button and you can set the content on button itself.
















Recent Activities


Sumit Kesarwani added new Question What is the Vector class in java?   yesterday

Anchal Kesharwani added new Blog JSON Syntax   8 days ago

Anchal Kesharwani added new Article How to Send Mail in Node.JS   8 days ago

Top Contributors

Don't want to miss updates? Please click the below button!