.ScaleControl 的 WPF 版本?
Control 的 WPF 版本是什么.ScaleControl
?
我试图通过将字体设置为 IconTitleFont:
private void ApplyUserFontPreferences()
{
this.FontFamily = SystemFonts.IconFontFamily;
this.FontSize = SystemFonts.IconFontSize;
this.FontStyle = SystemFonts.IconFontStyle;
this.FontWeight = SystemFonts.IconFontWeight;
}
与WinForms不同,表单的内容不会随着字体变化而缩放:
Before
之后(不好)
实际上表单上的所有控件(包括按钮的大小、列表视图列的宽度等)应缩放以匹配新布局:
之后(好)
因为 WPF 没有 (与 WinForms 不同)响应字体大小更改,我打算通过尝试缩放来解决该问题我自己使用 WPF 形式,使用 的假设 WPF 版本ScaleControl
:
private void ApplyUserFontPreferences()
{
Double scaleFactor = (SystemFonts.IconFontSize / this.FontSize); //i.e. new / old
this.ScaleControl(scaleFactor); //doesn't exist
this.FontFamily = SystemFonts.IconFontFamily;
// this.FontSize = SystemFonts.IconFontSize;
this.FontStyle = SystemFonts.IconFontStyle;
this.FontWeight = SystemFonts.IconFontWeight;
}
想要缩放控件(和所有子控件)的另一个示例是当我需要缩放控件(和所有子控件)以适合给定大小时。在这种情况下,我不想缩放整个表单,我只想缩放特定的控件。
What is the WPF version of Control.ScaleControl
?
i am trying to honor the user's font preference by setting the font to the IconTitleFont:
private void ApplyUserFontPreferences()
{
this.FontFamily = SystemFonts.IconFontFamily;
this.FontSize = SystemFonts.IconFontSize;
this.FontStyle = SystemFonts.IconFontStyle;
this.FontWeight = SystemFonts.IconFontWeight;
}
Unlike WinForms, the contents of the form are not scaled with the font change:
Before
After (bad)
In reality all controls on the form (including the size of buttons, the width of listview columns, etc) should scale to match the new layout:
After (good)
Since WPF doesn't (unlike WinForms) respond to font sizes changes, i was going to workaround the issue by trying to scale the WPF form myself, using a hypothetical WPF version of ScaleControl
:
private void ApplyUserFontPreferences()
{
Double scaleFactor = (SystemFonts.IconFontSize / this.FontSize); //i.e. new / old
this.ScaleControl(scaleFactor); //doesn't exist
this.FontFamily = SystemFonts.IconFontFamily;
// this.FontSize = SystemFonts.IconFontSize;
this.FontStyle = SystemFonts.IconFontStyle;
this.FontWeight = SystemFonts.IconFontWeight;
}
Another example of wanting to scale a control (and all child controls) is when i need to scale a control (and all child controls) to fit in a given size. In this case i don't want to scale an entire form, i only want to scale a particular control.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这个解决方案怎么样
?在后面的代码中
What about this solution
And in the code behind
我不确定它是否完全匹配您正在寻找的内容,但 WPF 确实包含自动缩放控件:Viewbox。
这有点严厉,所以 YMMV。最终,您可能会发现您需要更精确的控制,因此您必须谨慎设计模板等。但是,Viewbox 将为您提供一些基本的缩放功能。
另请参阅:分辨率WPF 中的独立性
I'm not sure if it matches exactly what you are looking for, but WPF does include an automatic scaling control: Viewbox.
It's a bit heavy-handed, so YMMV. Eventually, you'll probably find that you want more precise control, so you'll have to instead take care in designing your templates and so forth. However, Viewbox will get you some basic scaling functionality.
See also: Resolution Independance in WPF