首页 > 解决方案 > 在 ViewBox 内缩放 ComboBox 弹出窗口

问题描述

我正在开发一个 UWP 应用程序,并注意到 ComboBox 元素(只是弹出窗口)在放置在 ViewBox 内时缩放不正确。这是它的外观:

在此处输入图像描述

此外,由于 ComboBox 检测似乎偏离了实际的鼠标位置,因此选择了错误的元素。ComboBox 与网格内的其他元素并排放置(它是 ViewBox 的直接子元素)。其他一切都可以正常工作并且无需拉伸即可扩展。

有什么办法可以在保留 ViewBox 的同时解决这个问题?提前致谢!

编辑:

    <Viewbox>
        <Grid Width="1920" Height="1280" HorizontalAlignment="Center">
            <ComboBox HorizontalAlignment="Center" VerticalAlignment="Center" Width="200" Height="50">
                <ComboBoxItem Content="Test123"></ComboBoxItem>
                <ComboBoxItem Content="Test456"></ComboBoxItem>
                <ComboBoxItem Content="Test789"></ComboBoxItem>
            </ComboBox>
        </Grid>
    </Viewbox>

这几乎就是我想做的所有事情,我需要应用程序可以调整大小并且只支持特定的分辨率(1920x1280)。它需要以某种方式适应所有可能的 Windows 缩放设置。

标签: c#xamluwpwindows-10win-universal-app

解决方案


似乎是Windows 团队最近引入的一个错误。链接帖子中建议的修复方法之一是在 上添加不可见的旋转ViewBox

<Viewbox>
    <Viewbox.RenderTransform>
        <RotateTransform Angle="0.001"></RotateTransform>
    </Viewbox.RenderTransform>
    <Grid Width="1920" Height="1280" HorizontalAlignment="Center">
        <ComboBox HorizontalAlignment="Center" VerticalAlignment="Center" Width="200" Height="50">
            <ComboBoxItem Content="Test123"></ComboBoxItem>
            <ComboBoxItem Content="Test456"></ComboBoxItem>
            <ComboBoxItem Content="Test789"></ComboBoxItem>
        </ComboBox>
    </Grid>
</Viewbox>

当然这很恶心,这就是为什么微软建议遵循本指南来寻找替代想法(没有ViewBox不应该用来保持应用程序响应的想法)。


推荐阅读