用图片和文字在WPF按钮模板 [英] 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 simliar question
<一个href=\"http://stackoverflow.com/questions/1933127/creating-an-imagetext-button-with-a-control-template\">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?
感谢
推荐答案
没有。将你绑定什么 Image.Source
来?你需要的一个的DependencyProperty。当然,你也可以定义一个普通类,它包含两个属性:文本
和的ImageSource
或乌里
,然后用一个DataTemplate来呈现这一类的实例,但是这将是更code写的,这是一个有点臭。
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?
这篇关于用图片和文字在WPF按钮模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!