How to set the window's size in a Universal app?

不问归期 提交于 2019-12-08 02:45:24

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!