1

I am creating one sample WPF-MVVM application , in that I have one image which indicates '+' sign and I have a button with content 'Edit'. Now I have to show the image along with Name 'Edit' on a button. Please let me know the solution for this problem.

EDIT

here I am able to show the image but the name is appered below the image. But I want to show the name beside the image.

Pranay Rana
  • 175,020
  • 35
  • 237
  • 263
skumar
  • 437
  • 2
  • 4
  • 12

2 Answers2

2

you can do something like this

    <Button Margin="104,78,84,60" Name="button1" Height="100" Width="200">
            <StackPanel Orientation="Horizontal">
                <Image Source="ssv.png" Stretch="None" Height="50" Width="50" />
                <TextBlock TextAlignment="Center">Text value for this.</TextBlock>
            </StackPanel>
    </Button>
Pranay Rana
  • 175,020
  • 35
  • 237
  • 263
  • Hi Pranay here I am able to show the image but the name is appered below the image. But I want to show the name beside the image. – skumar Sep 12 '12 at 07:49
  • @skumar - you might need to add Orientation="Horizontal" as i did in update and might need to increase width.. – Pranay Rana Sep 12 '12 at 07:52
  • Thank you very much pranay... Now i am able to show image along with text – skumar Sep 12 '12 at 08:08
  • @skumar If this answer solved your problem, you should set it as the accepted answer. – Eirik Sep 12 '12 at 08:40
0

There are a few ways you could create an 'image button', one way would be to create a custom which derives from Button and adds an Image property, or a user control that uses a Button and declaratively adds the image as part of the buttons's control template in the user control XAML.

However, these approaches mean that the layout of the image within the button is fixed, so it isn't particularly flexible.

A nicer option is to create an attached property which stores the image location, and then reference this attached property value in the buttons control template. You can then create a style for the control template to make the layout reusable across buttons.

devdigital
  • 34,151
  • 9
  • 98
  • 120