问题
I use C# and XAML, and my main page begins like this :
<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>
But the windows is always maximized when I start the app. Only the grid respects the size mentionned in the XAML. I read some answers on this forum, but I have compilation errors when I write :
ResizeMode="NoResize"
in the XAML code, or
Application.Current.MainWindow.Height = 754;
in the C# code (because Application.Current is known, but not Application.Current.MainWindow).
I can't figure out why those solutions don't work for me. I could see this too :
WindowState="Maximized"
ResizeMode="NoResize"
WindowStyle="None"
It doesn't work either : "It doesn't exist in the context". What's wrong ?
回答1:
In App.xaml.cs before Window.Current.Activate(); you should paste:
ApplicationView.PreferredLaunchViewSize = new Size(1018, 754);
ApplicationView.PreferredLaunchWindowingMode = ApplicationViewWindowingMode.PreferredLaunchViewSize;
来源:https://stackoverflow.com/questions/40997790/how-to-set-the-windows-size-in-a-universal-app