缩放整个 WPF 窗口
我有一个 WPF 应用程序,将在大型高分辨率投影仪上向观众演示,但我担心该应用程序太小而无法从远处看到。
有没有一种简单的方法可以使整个应用程序更大(例如 WPF 设计器中的缩放滑块,可以放大?)我尝试在 XAML 中向窗口添加布局转换,如下所示:
<Window.LayoutTransform>
<ScaleTransform ScaleX="1.5" ScaleY="1.5" CenterX=".5" CenterY=".5" />
</Window.LayoutTransform>
这使得窗口在设计器,但似乎对正在运行的应用程序没有影响。
我想这应该是非常简单的WPF的“分辨率独立”,高科技文本渲染,矢量图形等
(我知道我可以使用屏幕缩放工具,但这很蹩脚,因为它使一切变得模糊,并且总是让我头晕当演示者在屏幕上平移时。)
I have a WPF application that I am going to be demoing to an audience on a large, high-resolution projector, and I am worried that the application will be too small to see from afar.
Is there a simple way to make the ENTIRE application bigger (like the zoom slider in the WPF designer, that lets you zoom in?) I tried adding a layout transform to the Window in XAML, like so:
<Window.LayoutTransform>
<ScaleTransform ScaleX="1.5" ScaleY="1.5" CenterX=".5" CenterY=".5" />
</Window.LayoutTransform>
which makes the window look bigger in the designer, but seems to have no effect on the running application.
I figure this should be dead simple with WPF's "resolution independence", high-tech text rendering, vector graphics, etc.
(I know I can use a screen zooming tool, but that's lame since it makes everything fuzzy, and always makes me dizzy when the presenter pans around the screen.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
刚刚意识到,将转换放在顶级控件(在我的例子中是
网格
)上,而不是窗口本身上,可以与我正在寻找的效果类似。唯一的区别是窗口大小没有改变,所以一切看起来都有点局促,但是通过增大窗口可以很容易地解决这个问题。Just realized that putting the transform on the top-level control (a
Grid
, in my case), instead of on the window itself, has a similar effect to what I was looking for. The only difference is that the window size doesn't change so everything looks a little cramped, but that is easily remedied by making the window larger.我在另一个问题中发布了一个相当详细的缩放主要元素的示例一个>。或许它对你会有一些用处。
I posted a fairly detailed example of scaling the main element in another question. Perhaps it would be of some use to you.
使用 ViewBox 是使整个应用程序更大(甚至字体大小)的最简单方法。
在这里你可以找到一些关于ViewBox的讨论。
Using ViewBox would be the simplest way to make an entire application bigger, even the font size.
Here you can find some discussion about ViewBox.
工作解决方案
至少在 WPF .NET Core 3.1
Window
中支持SizeToContent="WidthAndHeight"
,它也可以与旧版本一起使用,因为自 .NET Framework 3.0 以来就支持此属性。结合内容控件的固定宽度/高度和
LayoutTransform
上设置的ScaleTransform
,它缩放整个窗口。配方
SizeToContent
:宽度和高度
LayoutTransform
:您的自定义ScaleTransform
注意
通过样式设置
SizeToContent
不起作用(这个过程似乎太晚了)。示例 XAML
Working Solution
At least in WPF .NET Core 3.1
Window
supportsSizeToContent="WidthAndHeight"
, it may work with older versions also as this property is supported since .NET Framework 3.0.Combined with a fixed width/height of the content control and a
ScaleTransform
set onLayoutTransform
, it scales the entire window.Recipe
SizeToContent
:WidthAndHeight
LayoutTransform
: your customScaleTransform
Note
Setting
SizeToContent
by a style doesn't work (seems too late in the process).Sample XAML