在 Silverlight 中,如何调整包含两个 TextBlock 的按钮的宽度?
我有一个按钮,其内容模板包含两个 TextBlock。如何对按钮进行编程以适应文本块中的文本量?
我只知道运行时按钮中输入的文本是什么,而不是设计时。
我试图将 TextBlock 放入 Viewbox 中,但 ViewBox 只能有一个子元素。
谢谢, 标记
I have a button, the content template of which contains two TextBlocks. How can I program the button to adjust to the amount of text in the TextBlocks?
I only know what text is going into the buttons at run time, not design time.
I was trying to go down the road of putting the TextBlocks in a Viewbox, but a ViewBox can only have one child element.
Thanks,
Mark
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将 2 个 TextBlock 放入 Grid 或 StackPanel 中(取决于您希望它们如何定向),并且不设置任何宽度属性。这样,宽度将默认为自动。如果您希望按钮在“文本”属性为空时可见,请设置“最小宽度”。
Put the 2 TextBlock's inside a Grid or a StackPanel (depending on how you want them oriented), and don't set any Width Attributes. That way, Width will default to Auto. Set a MinWidth if you would like the Button to be visible when the Text attributes are empty.
ViewBox 是可选的,具体取决于您是否希望按钮具有固定宽度并适合所有内容(然后,您需要它)或者是否希望按钮宽度增长(然后将其保留)
The ViewBox is optional, depending on if you want the button to be fixed-width and fit all the content (then, you want it) or if you want to button width to grow (then leave it out)