我有一个WPF应用程序,我将在大型高分辨率投影仪上向观众演示,我担心应用程序太小而无法远远看到。
是否有一种简单的方法可以使整个ENTIRE应用程序更大(比如WPF设计器中的缩放滑块,可以放大?)我尝试在XAML中向窗口添加布局转换,如下所示:
<Window.LayoutTransform>
<ScaleTransform ScaleX="1.5" ScaleY="1.5" CenterX=".5" CenterY=".5" />
</Window.LayoutTransform>
使得窗口在设计器中看起来更大,但似乎对正在运行的应用程序没有任何影响。
我认为这应该是WPF的“分辨率独立性”,高科技文本渲染,矢量图形等等。
(我知道我可以使用屏幕缩放工具,但这很蹩脚,因为它会使一切变得模糊,并且当演示者在屏幕周围平移时总是让我晕眩。)
答案 0 :(得分:11)
刚刚意识到将转换放在顶级控件(在我的情况下是Grid
),而不是在窗口本身上,与我所寻找的效果相似。唯一的区别是窗口大小没有变化所以一切看起来都有点狭窄,但通过使窗口变大可以很容易地解决这个问题。
答案 1 :(得分:7)
我发布了一个相当详细的扩展主元素in another question的例子。也许这会对你有所帮助。
答案 2 :(得分:6)
答案 3 :(得分:2)
至少在WPF .NET Core 3.1 Window
中支持SizeToContent="WidthAndHeight"
,它也可以与旧版本一起使用,因为自.NET Framework 3.0开始支持此属性。
结合内容控件的固定宽度/高度和在ScaleTransform
上设置的LayoutTransform
,它可以缩放整个窗口。
SizeToContent
:WidthAndHeight
LayoutTransform
:您的自定义ScaleTransform
用样式设置SizeToContent
无效(似乎太迟了)。
<Window x:Class="Some.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Some"
mc:Ignorable="d"
Title="MainWindow"
SizeToContent="WidthAndHeight"
>
<Window.Resources>
<ResourceDictionary>
<ScaleTransform x:Key="windowScaleTransform" ScaleX="0.5" ScaleY="0.5" />
</ResourceDictionary>
</Window.Resources>
<Grid Width="1080"
Height="1920"
LayoutTransform="{StaticResource windowScaleTransform}"
>
<TextBlock>This window is scaled to 50%!</TextBlock>
</Frame>
</Window>