Add icon to button with Visual Studio

18,269

Solution 1

The easiest/best way to do this is to add an Image control as the Content of the Button.

The property window is somewhat limited in what it can do, and only supports text for that property. This does include bindings, so you could use an Image StaticResource. I couldn't find an easy way to create one from the property designer either though.

So basically, you are stuck with editing XAML. Either with a direct Content property or by creating an element in Resources Its not that bad! Just write:

<Button>
   <Button.Content>
      <Image ImageSource="..."/>
   </Button.Content>
</Button>

Now of course, you could create a custom button that exposed that property via the designer, but thats even more XAML. Its WPF, you are going to have to write XAML, so learning how should be a priority.

Solution 2

Visual Studio 2015: create a button. create an image. set the source of the image to the right file of your resources (e.g. a .png file that you included to your project) drag the image over the button. A text shows that asks you to press ALT to replace the text of the button with the image.

I currently don't know how to get both, image and text, for a button.

in XAML, it looks like this:

<Button x:Name="button12" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" Width="75">
   <Image x:Name="image" HorizontalAlignment="Left" Height="24" VerticalAlignment="Top" Width="24" Source="gfx/new.png"/>
</Button>
Share:
18,269
tempname11112
Author by

tempname11112

Updated on June 27, 2022

Comments

  • tempname11112
    tempname11112 almost 2 years

    I have a simple question. I want to add an icon to a C# WPF Button control. I do not want to have to write C# code, or edit XAML to do this.

    However, when I click on the button in the Designer, there is no option under properties to set an image. How do you do this through the Visual Studio GUI?

    • Dai
      Dai over 9 years
      Add the image as a child control of the button.
    • MethodMan
      MethodMan over 9 years
      this is not that trivial its why not use a ImageButton is that an option..?