如何在通用应用程序中设置 window 的大小?
How to set the window's size in a Universal app?
我使用 C# 和 XAML,我的主页是这样开始的:
<Page
x:Class="MyApp.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:MyApp"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Height="754" Width="1018" MaxHeight="754" MaxWidth="1018" MinHeight="754" MinWidth="1018"
mc:Ignorable="d">
<Grid>
(...)
</Grid>
但是当我启动应用程序时,windows 总是最大化。只有网格尊重 XAML 中提到的大小。我在这个论坛上看了一些答案,但是我写的时候有编译错误:
ResizeMode="NoResize"
在XAML代码中,或
Application.Current.MainWindow.Height = 754;
在 C# 代码中(因为 Application.Current 是已知的,但 Application.Current.MainWindow 不是已知的)。
我不明白为什么这些解决方案对我不起作用。我也能看到这个:
WindowState="Maximized"
ResizeMode="NoResize"
WindowStyle="None"
它也不起作用:"It doesn't exist in the context"。怎么了?
在 App.xaml.cs 之前 Window.Current.Activate(); 你应该粘贴:
ApplicationView.PreferredLaunchViewSize = new Size(1018, 754);
ApplicationView.PreferredLaunchWindowingMode = ApplicationViewWindowingMode.PreferredLaunchViewSize;
我使用 C# 和 XAML,我的主页是这样开始的:
<Page
x:Class="MyApp.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:MyApp"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Height="754" Width="1018" MaxHeight="754" MaxWidth="1018" MinHeight="754" MinWidth="1018"
mc:Ignorable="d">
<Grid>
(...)
</Grid>
但是当我启动应用程序时,windows 总是最大化。只有网格尊重 XAML 中提到的大小。我在这个论坛上看了一些答案,但是我写的时候有编译错误:
ResizeMode="NoResize"
在XAML代码中,或
Application.Current.MainWindow.Height = 754;
在 C# 代码中(因为 Application.Current 是已知的,但 Application.Current.MainWindow 不是已知的)。
我不明白为什么这些解决方案对我不起作用。我也能看到这个:
WindowState="Maximized"
ResizeMode="NoResize"
WindowStyle="None"
它也不起作用:"It doesn't exist in the context"。怎么了?
在 App.xaml.cs 之前 Window.Current.Activate(); 你应该粘贴:
ApplicationView.PreferredLaunchViewSize = new Size(1018, 754);
ApplicationView.PreferredLaunchWindowingMode = ApplicationViewWindowingMode.PreferredLaunchViewSize;