Search code examples
wpftemplatesbindingcustom-controls

Button template with image and text in wpf


I want to create buttons with images and text inside. For example, i would use different images and text for buttons like 'Browse folders' and 'Import'.

One of the options would be to use a template. I had a look at similar question

Creating an image+text button with a control template?

But is there any way by which I can bind the source of image without using a dependency property or any other class?


Solution

  • No. What would you bind the Image.Source to? You need a DependencyProperty for this. Of course, you could also define a normal class which contains two properties: Text and ImageSource or Uri, and then use a DataTemplate to render instances of this class, but that would be even more code to write, and it is a little "smelly".

    What is the reason you do not want to use a dependency property or a custom class?