WPF ContextMenu 文本对齐
我正在为 WPF 应用程序构建一个上下文菜单,如果我有文本,然后添加图像,则文本始终与菜单项的顶部对齐,并且我不知道如何将其与中心对齐。
我已经尝试了 VerticalAlignment
和 VerticalContentAlignment
属性,但它们没有帮助......有什么想法吗?
I am building a context menu for a WPF application and if I have text and then I add an image, the text is always aligned at the top of the menu item and I can't figure out how to align it to the center.
I have tried the VerticalAlignment
and VerticalContentAlignment
properties but they dont help.. any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我想这取决于您使用哪种面板来承载文本和图像。 我尝试使用
StackPanel
,添加VerticalAlignment="Center"
后,文本就正确对齐了。 如果仍然无法解决您的问题,请提供更多信息。I guess it depends on what kind of panel you are using to host the text and the image. I tried with a
StackPanel
and once I addedVerticalAlignment="Center"
, the text was aligned correctly. Please provide some more information if it still doesn't work out for you.每当我遇到这样的困难时,我都会启动 Snoop (https://github.com/snoopwpf/snoopwpf) 并用它来找出哪个控件对齐不正确。
Whenever I get stuck like this, I fire up Snoop (https://github.com/snoopwpf/snoopwpf) and use it to figure out which control is aligned incorrectly.