Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 ?

like image 371
Myosotis Avatar asked Dec 06 '16 14:12

Myosotis


People also ask

How do I set custom window sizes?

Press Alt + Space shortcut keys together on the keyboard to open the window menu. Now, press S. The mouse cursor will turn into a cross with arrows. Use the left, right, up and down arrow keys to resize your window.

How do I make all my windows the same size?

Click and hold this black bar, then drag it left or right to resize the two windows simultaneously. The two windows will still combine to take up your entire display, but they will resize accordingly.

How do I use Universal Windows app?

Step 1: Go to Visual Studio 2015 update 3. Open Visual Studio New-->New project -->select Visual C# --->select Windows -->Universal -->select Blank Windows Universal App and give your app; a name (ex: sample). Step 2: Next step is to select the target version of Windows 10 SDK (Windows 10 Build 10240).

How do I make my Windows app smaller?

Right-click (or press and hold) the desktop, point to View, and then select Large icons, Medium icons, or Small icons. Tip: You can also use the scroll wheel on your mouse to resize desktop icons. On the desktop, press and hold Ctrl while you scroll the wheel to make icons larger or smaller.


1 Answers

In App.xaml.cs before Window.Current.Activate(); you should paste:

        ApplicationView.PreferredLaunchViewSize = new Size(1018, 754);
        ApplicationView.PreferredLaunchWindowingMode = ApplicationViewWindowingMode.PreferredLaunchViewSize;
like image 168
Jet Chopper Avatar answered Sep 29 '22 09:09

Jet Chopper