【问题标题】:Scaling ComboBox Popup inside ViewBox在 ViewBox 内缩放 ComboBox 弹出窗口
【发布时间】:2020-03-03 10:13:57
【问题描述】:

我正在开发一个 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 缩放设置。

【问题讨论】:

  • 您好,请提供您的代码或 XAML,以便我们提供帮助。
  • @CorentinPane 抱歉,已编辑

标签: c# xaml uwp windows-10 win-universal-app


【解决方案1】:

seems to be a bug 最近由 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>

这肯定很恶心,这就是为什么 Microsoft 建议关注 this guide 以寻找替代想法(没有 ViewBox 不应该用于保持应用响应)。

【讨论】:

  • 非常感谢!奇怪的解决方法,但它解决了我的问题。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-02-12
  • 2017-08-13
  • 1970-01-01
  • 2021-01-01
  • 1970-01-01
  • 2011-04-27
  • 1970-01-01
相关资源
最近更新 更多