我有一个为分配的访问权限(Kiosk 模式)创建的 Xamarin UWP 应用程序。 现在,在新屏幕上,默认缩放设置为 150%,我的应用程序在 100% 下看起来不错。 有人找到了更改创建的自助服务终端用户的默认缩放比例的方法吗?
尝试使用注册表版本更改 DPI 设置,但没有成功。
UWP 没有 API 可以直接在应用程序中设置比例。但 UWP 可以通过 DisplayInformation 获取系统当前的比例,因此我们可以根据当前的比例大小来修改控件的大小。
您可以参考官方示例DpiScaling。以下是基于示例的解决方案。 Button控件通过控制Button的属性
FontSize
.在不同比例下保持相同的大小
private double oldRawPixelsPerViewPixel;
public MainPage()
{
this.InitializeComponent();
DisplayInformation displayInformation = DisplayInformation.GetForCurrentView();
displayInformation.DpiChanged += DisplayInformation_DpiChanged;
oldRawPixelsPerViewPixel = 1.0; // your app is looking good on 100%.
button.FontSize= PxFromPt(20); //default fontsize
}
private void ResetOutput()
{
DisplayInformation displayInformation = DisplayInformation.GetForCurrentView();
double rawPixelsPerViewPixel = displayInformation.RawPixelsPerViewPixel;
double fontSizeInViewPx = button.FontSize / (rawPixelsPerViewPixel / oldRawPixelsPerViewPixel);
button.FontSize = fontSizeInViewPx;
oldRawPixelsPerViewPixel = rawPixelsPerViewPixel;
}
private void Page_Loaded(object sender, RoutedEventArgs e)
{
ResetOutput();
}
private void DisplayInformation_DpiChanged(DisplayInformation sender, object args)
{
ResetOutput();
}
// Helpers to convert between points and pixels.
double PtFromPx(double pixel)
{
return pixel * 72 / 96;
}
double PxFromPt(double pt)
{
return pt * 96 / 72;
}