【问题标题】:Scale/zoom UWP app automatically from HD to 4K自动从 HD 缩放/缩放 UWP 应用程序到 4K
【发布时间】:2018-04-16 09:53:23
【问题描述】:

有没有办法在 4K 屏幕中复制应用程序的高清布局(使它们看起来完全相同),而无需手动计算 4K 屏幕的所有字体大小、边距、填充等,而不是必须在 VisualState 触发器中设置它们?

这是我当前解决方案的示例:

<VisualStateManager.VisualStateGroups>
    <VisualStateGroup>
        <VisualState x:Name="ScreenWidthHDState">
            <VisualState.StateTriggers>
                <AdaptiveTrigger MinWindowWidth="{StaticResource ScreenWidthHD}" />
            </VisualState.StateTriggers>
            <VisualState.Setters>
                <Setter Target="SampleTextBlock.FontSize" Value="{StaticResource RegularFontSize}" />
                <Setter Target="SampleGrid.Margin" Value="6" />
            </VisualState.Setters>
        </VisualState>
    </VisualStateGroup>
    <VisualStateGroup>
        <VisualState x:Name="ScreenWidth4KState">
            <VisualState.StateTriggers>
                <AdaptiveTrigger MinWindowWidth="{StaticResource ScreenWidth4K}"/>
            </VisualState.StateTriggers>
            <VisualState.Setters>
                <Setter Target="SampleTextBlock.FontSize" Value="{StaticResource RegularFontSize4K}" />
                <!-- I'm multiplying the original value (6) by 1.33333 to achieve the exact same layout in 4K that I have in HD -->
                <!-- 4K resolution in effective pixels is 2560 wide (2560/1920 = 1.3333333...) -->
                <Setter Target="SampleGrid.Margin" Value="8" />
            </VisualState.Setters>
        </VisualState>
    </VisualStateGroup>
</VisualStateManager.VisualStateGroups>

这可行,但问题是我们在这里所拥有的并不是真正的响应式/自适应设计实现,只是要在 4K 中显示的高清布局的缩放/缩放副本,因此您不会注意到两者之间的区别。通过将“显示设置”中的 Windows 自定义缩放更改为 200% 并使用 3840x2160 的分辨率,可以实现相同的效果,但这需要相应地配置每台客户端计算机,这不是一个选项。

您可以想象,手动计算应用程序中每个元素的尺寸以使其在 HD 和 4K 中看起来完全相同是一种乏味、耗时且不可扩展的解决方案。我尝试以几种不同的方式使用 ViewBox,但结果远非理想,因为在以不同方式调整应用程序窗口大小后,我无法控制布局的实际外观。简单地使用具有 ScaleX/ScaleY 值的 CompositeTransform 会使应用程序越界并强制滚动条,这也是不可接受的。

有什么解决方案可以检测屏幕分辨率并神奇地缩放/缩放应用,使其在高清和 4K 下看起来完全一样?

【问题讨论】:

    标签: uwp zooming scaling uwp-xaml screen-resolution


    【解决方案1】:

    只有在 UWP 应用在 Xbox One 上运行时才能关闭缩放

    bool result = 
       Windows.UI.ViewManagement.ApplicationViewScaling.TrySetDisableLayoutScaling(true);
    

    但我认为没有任何类似的语法可以在桌面上强制缩放。

    缩放是操作系统内置的,应用会自动考虑用户为系统设置的缩放这一事实通常是优势而不是劣势。

    换种说法 - 如果应用程序在 4K 显示器上设置为 100% 时有小字体等,那么问题不仅出在您的应用程序中,而且在该设备上的所有应用程序中,在这种情况下,用户要么有意识地选择这种显示设置,或者她应该考虑在系统范围内更改它们,而不是针对特定应用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-16
      • 2011-05-31
      • 2018-08-07
      • 2016-12-14
      • 2019-11-07
      • 2018-09-12
      相关资源
      最近更新 更多