How to set fixed window size for universal Windows application

I just started developing a universal Windows application in VS2015 Community Edition. I used a sample called PieCharts for Windows UWP.

My problem is that I would like to set the window size to 400x650, as it was in old desktop applications. I set the width and height manually. This does not work. My MainPage.xaml is something like the following code.

<Page x:Class="MyFistUWP.MainPage"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:local="using:MyFistUWP"
  xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
  xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
  MaxHeight="650" MinHeight="650" MaxWidth="400" MinWidth="400" Height="650" Width="400" >

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="140" />
        <RowDefinition Height="*" />
    </Grid.RowDefinitions>

    <Image Grid.Row="0" Source="Resources/my_logo.png" />
</Grid>

The window size is wrong and I can resize the window.

Thank,

+4
source share
3 answers

:   ApplicationView.GetForCurrentView().SetPreferredMinSize(new Size(400, 650));

+2

, OnSizeChanged . . , , .

private void FormName_SizeChanged(object sender, SizeChangedEventArgs e)
{
    if((this.Width != 400) & (this.Height != 650))
    {
        this.Width = 450;
        this.Height = 650;
    }
}
0

I have found a solution. I think this is not the best, but it works.
XAML:

     <Grid Background="#4A9130" SizeChanged="FormName_SizeChanged">

WITH#

    private void FormName_SizeChanged(object sender, SizeChangedEventArgs e)
    {

        ApplicationView.GetForCurrentView().TryResizeView(new Size(900, 600));
    }

Hope this helps

0
source

All Articles