c# - 在 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 缩放设置。
解决方案
这似乎是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
不应该用来保持应用程序响应的想法)。
推荐阅读
- sql - 为什么这个 sql select 选择所有内容 3 次
- ffmpeg - ffmpeg 无法识别记录在案的 ffmpeg 命令
- javascript - 如何在使用 Typescript 进行渲染时剪切短长的字符串
- java - Android Studio 其他活动打不开
- docker - nexus 作为 docker 存储库
- facebook-opengraph - 我真的需要 xmlns 或前缀来使用 opengraph 元标记吗?
- php - 我的 PHP Mail() 函数不会发送电子邮件
- sql - 在 SQL Server 数据库的所有表中搜索特定的二进制列
- python - Kivy 标签的位置
- python - 从具有不同格式的不同来源中提取具有相似数据的 HTML 表 - Python