如何禁用 UWP 应用程序的缩放
How to disable scaling for UWP apps
我正在设计 uwp 应用程序。我的电脑分辨率是 1920 x 1080,100% 比例。所有元素都是正常布局。
但是当 运行 应用程序在 1920 x 1080、125% 比例的屏幕上显示时,元素不在正确的位置,所有元素都大了 1.25 倍。
那么如何在所有分辨率下禁用缩放,或者有什么解决办法吗?
我给你一个简单的例子,我在其中展示了两个按钮和一个网格,你可以 运行 在任何分辨率下,左右手边的按钮总是保持在相同的位置,网格会相应地改变分辨率大小
<Grid HorizontalAlignment="Stretch" Margin="0,0,0,0" VerticalAlignment="Stretch" >
<Grid.RowDefinitions>
<RowDefinition Height="150"/>
<RowDefinition Height="169*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="150"/>
<ColumnDefinition Width="113*"/>
<ColumnDefinition Width="150"/>
</Grid.ColumnDefinitions>
<Button Content="Button" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="10,55,10,40" />
<Button Content="Button" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="10,55,10,40" Grid.Column="2" />
<Grid Grid.Column="1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" BorderBrush="Black" BorderThickness="2" Grid.RowSpan="2"/>
</Gid>
您的代码示例
<Grid HorizontalAlignment="Stretch" Margin="0,0,0,0" VerticalAlignment="Stretch" >
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="945"/>
<ColumnDefinition Width="945"/>
</Grid.ColumnDefinitions>
<TextBlock Text="Color"
Margin="117, 84, 0, 0"
FontSize="48"/>
<Button Grid.Row="1" Content="Red" Width="500" Height="80" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
Margin="445 30 0 0"
/>
<Button Grid.Row="1" Grid.Column="1" Content="Yellow" Width="500" Height="80"
Margin="0 30 445 0"
HorizontalAlignment="Center" VerticalAlignment="Center"/>
<Grid Grid.Row="2" Grid.ColumnSpan="2"
Margin="84 40 84 0" HorizontalAlignment="Stretch"
VerticalAlignment="Stretch" BorderBrush="Black" BorderThickness="2"/>
</Grid>
我正在设计 uwp 应用程序。我的电脑分辨率是 1920 x 1080,100% 比例。所有元素都是正常布局。 但是当 运行 应用程序在 1920 x 1080、125% 比例的屏幕上显示时,元素不在正确的位置,所有元素都大了 1.25 倍。
那么如何在所有分辨率下禁用缩放,或者有什么解决办法吗?
我给你一个简单的例子,我在其中展示了两个按钮和一个网格,你可以 运行 在任何分辨率下,左右手边的按钮总是保持在相同的位置,网格会相应地改变分辨率大小
<Grid HorizontalAlignment="Stretch" Margin="0,0,0,0" VerticalAlignment="Stretch" >
<Grid.RowDefinitions>
<RowDefinition Height="150"/>
<RowDefinition Height="169*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="150"/>
<ColumnDefinition Width="113*"/>
<ColumnDefinition Width="150"/>
</Grid.ColumnDefinitions>
<Button Content="Button" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="10,55,10,40" />
<Button Content="Button" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="10,55,10,40" Grid.Column="2" />
<Grid Grid.Column="1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" BorderBrush="Black" BorderThickness="2" Grid.RowSpan="2"/>
</Gid>
您的代码示例
<Grid HorizontalAlignment="Stretch" Margin="0,0,0,0" VerticalAlignment="Stretch" >
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="945"/>
<ColumnDefinition Width="945"/>
</Grid.ColumnDefinitions>
<TextBlock Text="Color"
Margin="117, 84, 0, 0"
FontSize="48"/>
<Button Grid.Row="1" Content="Red" Width="500" Height="80" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
Margin="445 30 0 0"
/>
<Button Grid.Row="1" Grid.Column="1" Content="Yellow" Width="500" Height="80"
Margin="0 30 445 0"
HorizontalAlignment="Center" VerticalAlignment="Center"/>
<Grid Grid.Row="2" Grid.ColumnSpan="2"
Margin="84 40 84 0" HorizontalAlignment="Stretch"
VerticalAlignment="Stretch" BorderBrush="Black" BorderThickness="2"/>
</Grid>