如何制作具有多个内容值的按钮?
我的目标是制作一个具有两个内容值的按钮。
将拼字游戏图块想象成一个按钮:它的中间有一个大字母,右下角有一个小数字。 这就是我想要的效果。
我制作了一个按钮,其中有两个 ContentPresenter 对象,并且为每个 ContentPresenter 指定了不同的样式。 但是,我还没有找到一种方法来为每个演示者提供单独的值(即,如果我将按钮的内容设置为“X”,则两个 ContentPresenter 都显示“X”,尽管样式不同)。
我怎样才能实现我的目标? 我猜我的方法是完全错误的......
My goal is to make a Button that has two Content values.
Imagine a Scrabble tile as a button: it has the large letter in the center and a small number in the lower right. This is the effect I am going for.
I made a button that has two ContentPresenter objects in it, and I have given each of the ContentPresenters a different style. However, I have not found a way to give each of the presenters a separate value (ie, if I set the Content of the button to "X" then both ContentPresenters show "X", albeit in different styles).
How can I achieve my objective? I'm guessing my approach is completely wrong....
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
呸……我想我现在知道该怎么做了。 我应该制作自己的控件而不是修改按钮。 如果我在 WinForms 中工作,这对我来说是显而易见的,但出于某种原因,所有这些 Xaml 让我变得愚蠢。
Bah... I think I know what to do now. I should be making my own control rather than modifying a Button. This would have been obvious to me had I been working in WinForms, but for some reason all this Xaml is making me stupid.
查看 Expander 示例 ControlTemplate,网址为 http://msdn.microsoft.com /en-us/library/ms753296.aspx
Expander 是 HeaderedContentControl 的子类,它有两个“内容”: Header 和 Content
控件模板有两个 ContentPresenter 元素,ContentPresenter 没有绑定到默认的 content 属性定义为:
如果您需要使用 Button 并且不想为第二个内容添加另一个属性,您可以使用附加属性并将第二个 ContentPresnter Content 属性数据绑定到它。
Take a look at the Expander sample ControlTemplate at http://msdn.microsoft.com/en-us/library/ms753296.aspx
Expander is a subclass of HeaderedContentControl, it has two "contents": Header and Content
The control template has two ContentPresenter elements, the ContentPresenter that is not bound to the default content property is defined as:
<ContentPresenter ContentSource="Header" />
If you need to use a Button and you don't want to add another property for the second content you can use an attached property and data bind the second ContentPresnter Content property to it.
我用多个“内容槽”创建 UserControl 此处 - 它比从 HeaderedControl 派生更好,因为插槽数量不受限制。
使用示例:
I delaled with creating UserControl with multiple 'content slots' here - it's better than deriving from HeaderedControl as you aren't limited in the number of slots.
Sample usage: