Silverlight:我可以创建一个包含两个 TextBlock 的自定义按钮,每个 TextBlock 都绑定到对象上的不同属性吗?
我想制作类似于此网站上的按钮。
假设我正在使用的对象是 ArtPiece,并且有标题和日期。我希望这两个都显示在两个不同文本块中的按钮上。
我一直在尝试修改按钮的 ContentTemplate,然后修改 ContentTemplate 内按钮的 ContentPresenter,但我仍然无法绑定 TextBlock。
完全在 XAML 中完成此操作有什么帮助吗?我正在使用表达式 3。
I want to make buttons similar to those on this website.
Lets say that the object I'm working with is ArtPiece, and has a Title and Date. I want both of those to show up on my buttons in two different TextBlocks.
I've been trying to modify the button's ContentTemplate, then modifying the button's ContentPresenter inside the ContentTemplate, but I still can't get the TextBlocks to bind.
Any help getting this done entirely in XAML? I'm using Expression 3.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你想做这样的事情:
You want to do something like this:
听起来您真正想要的是某种多重绑定支持,将这两个属性绑定到按钮上的一个 Content 属性。据我所知,silverlight 中没有像 WPF 那样内置的多重绑定支持。相对= “nofollow noreferrer">本文概述了在 silverlight 中实现它的一种方法。
如果您使用 MVVM 模式,一种更简单的方法是在 ViewModel 中创建另一个属性,将两个字符串连接在一起,然后您可以将按钮的内容绑定到该单个新属性。在我看来,这将是一种更简单、更干净的方法。
It sounds like what you really want is some sort of multi-binding support to bind these two properties to one Content property on the button. As far as I know there is no built in multi-binding support in silverlight as there is in WPF. This article outlines one approach to implementing it in silverlight.
If you were using the MVVM pattern a much easier approach would be to create another property in your ViewModel which concatenated the two strings together and then you could just bind the Content of the button to that single new property. This would be a much simpler and cleaner approach in my opinion.