首页 > 解决方案 > WPF Visual Studio:主窗口无法缩放以适应 Windows 屏幕

问题描述

重新安装 Visual Studio 后,任何 WPF 项目中的主窗口都不再缩放为 Windows 中选择的比例。我已将屏幕的比例设置为 125%,并且在窗口和其中的所有文本都增大之前。现在,它是与 100% 比例保持相同大小的主窗口。如何解决?

除了重新安装之外,我唯一做的就是根据此处的说明设置值:url

setx VSXAML_DISABLE_ON_DEMAND_RESOURCE_VALUES 1

例子:

接口规模 125%

主窗口和对话窗口

两个窗户的尺寸 -Height="450" Width="800"

введите сюда описание изображения

缩放150%

введите сюда описание изображения

我提醒你,窗户的大小是一样的。

我能做些什么呢?


主窗口:

<Window x:Class="TestWpfApp.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:TestWpfApp"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800"
        Background="DarkGray">
    <Grid Background="#222222">
        <Grid.RowDefinitions>
            <RowDefinition/>
            <RowDefinition Height="50"/>
        </Grid.RowDefinitions>
        <Button x:Name="btn" Grid.Row="1" Content="Button"/>
    </Grid>
</Window>

对话:

<Window x:Class="TestWpfApp.Dialog"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:TestWpfApp"
        mc:Ignorable="d"
        Title="Dialog" Height="450" Width="800" Opacity="0.5">
    <Grid>
        <TextBlock Text="Test Text" FontSize="25"/>
    </Grid>
</Window>

标签: wpfvisual-studio

解决方案


推荐阅读