处理 WPF 应用程序中由于显示属性而导致的不同字体大小?
我的小组正在 WPF 中构建一个编辑器类型的应用程序。 我们注意到的一件事是,在我的 WinXP 机器上,运行“Windows 经典风格”主题时,按钮上的文本非常合适。 然而,在我朋友的机器上,他运行的是“windows xp style”主题,字体大小较大,因此按钮上的文本会被剪裁在底部。
有没有办法很好地处理这个问题,比如自动调整控件大小以适应文本?
我犹豫是否要手动调整按钮大小以适应他的布局,因为其他人可以通过“显示属性”和“辅助功能选项”进行完全不同的设置。
谢谢!
My group is building an editor-type app in WPF. One thing we noticed is that on my WinXP machine, running with the "windows classic style" theme, the text on buttons is fits fine. However on my friend's machine, who's running with the "windows xp style" theme, the font size is bigger so text on buttons get clipped at the bottom.
Is there a way to handle this nicely, like automatically resizing controls to fit the text?
I hesitate to manually resize the button to fit his layout as anyone else can have totally different settings through the Display Properties and Accessibility Options.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
WPF 按钮将自动调整大小以适应给定的内容,但是只有当它位于不强制大小的容器内且尚未手动设置其大小时,它才会执行此操作。 为了证明以下代码片段中字体大小的混乱:
我猜你的按钮没有调整大小,因为你限制了它们。 要解决此问题,您需要决定如何调整它们的大小(如果盲目增长,元素会重叠,这可能会非常复杂),并且如果提供的面板类型都没有执行您正在寻找的增长行为,那么您可能需要自己写一个就可以了。
A WPF button will automatically resize to fit the content that it has been given, however it will only do this when it is inside a container that does not enforce size and its size has not been set manually. To prove this mess around with the font size in the following code snippet:
I guess that your buttons haven't resized because you have constrained them. To fix this you need to decide how you want them to resize (which can be very complicated when elements would overlap if they just grew blindly) and if none of the supplied panel types perform the growth behaviour that you are looking for then you may need to write your own that does.
您是否使用 Width 和 Height 属性对元素大小进行了硬编码? 在 WPF 中,推荐的方法是使用多个布局容器。
以下是一个网格示例,该网格在底部放置两个按钮,在顶部放置一个文本框。
Have you hardcoded element sizes using Width and Height properties? In WPF the recommended way to do this is to use the several layout containers.
The following is an example of a grid which lays two buttons at the bottom and a textbox at the top.