缩放整个 WPF 窗口

发布于 2024-10-17 21:32:36 字数 454 浏览 2 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

素年丶 2024-10-24 21:32:36

刚刚意识到,将转换放在顶级控件(在我的例子中是网格)上,而不是窗口本身上,可以与我正在寻找的效果类似。唯一的区别是窗口大小没有改变,所以一切看起来都有点局促,但是通过增大窗口可以很容易地解决这个问题。

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.

帥小哥 2024-10-24 21:32:36

我在另一个问题中发布了一个相当详细的缩放主要元素的示例一个>。或许它对你会有一些用处。

I posted a fairly detailed example of scaling the main element in another question. Perhaps it would be of some use to you.

箹锭⒈辈孓 2024-10-24 21:32:36

使用 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.

抱猫软卧 2024-10-24 21:32:36

工作解决方案

至少在 WPF .NET Core 3.1 Window 中支持 SizeToContent="WidthAndHeight",它也可以与旧版本一起使用,因为自 .NET Framework 3.0 以来就支持此属性。
结合内容控件的固定宽度/高度LayoutTransform上设置的ScaleTransform,它缩放整个窗口

配方

  • 窗口
    • SizeToContent宽度和高度
  • 内容
    • 固定尺寸​​
    • LayoutTransform:您的自定义ScaleTransform

注意

通过样式设置 SizeToContent 不起作用(这个过程似乎太晚了)。

示例 XAML

<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>

Working Solution

At least in WPF .NET Core 3.1 Window supports SizeToContent="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 on LayoutTransform, it scales the entire window.

Recipe

  • Window
    • SizeToContent: WidthAndHeight
  • Content
    • Fixed size
    • LayoutTransform: your custom ScaleTransform

Note

Setting SizeToContent by a style doesn't work (seems too late in the process).

Sample XAML

<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>

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文