views:

354

answers:

1

Hello,

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 simliar question

http://stackoverflow.com/questions/1933127/creating-an-imagetext-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?

Thanks

+1  A: 

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?

gehho
The only reason is i wanted to know if there is any other simple way or you can say rather 'less-code' way to do it. With texblock i can use <TextBlock Text="{TemplateBinding Content}" /> I wanted to know why cant i do the same with the Source property of an Image?
Archie
But **where** would you put that `TemplateBinding`? And to **which property** would you bind?
gehho
Can I use 'Tag' property to bind it?
Archie
I am not sure. It might work. However, personally, I would consider this as pretty bad code because the intention is not clear, you do not have any type-safety... It is up to you.
gehho