CONVERT IMAGE TO A BUTTON WPF

Ankit Singh

Total Post:341

Points:2389
Posted by  Ankit Singh
WPF
 1219  View(s)
Ratings:
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.

  1. Sumit Kesarwani

    Post:378

    Points:2694
    Re: Convert image to a button WPF

    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.

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!