How to set fixed window size for Universal Windows Application

亡梦爱人 提交于 2019-12-23 11:53:40

问题


I just started to develop an Universal Windows Application in VS2015 Community Edition. I have used the sample called PieCharts for Windows UWP.

My problem is that I whould like to fix the window size to 400x650 as I did in my old desktop applications. I have set Width and Height manually It 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 window.

Thanks,


回答1:


You can use this code for set minimal size of application: ApplicationView.GetForCurrentView().SetPreferredMinSize(new Size(400, 650));




回答2:


I found a solution. I think its not the best, but it works.
XAML:

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

c#

    private void FormName_SizeChanged(object sender, SizeChangedEventArgs e)
    {

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

Hope it helps




回答3:


I guess the only choice is use OnSizeChanged Method to control size of window. It's work's for me. Maybe not the best choice but really easy way to solve problem.

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


来源:https://stackoverflow.com/questions/36065512/how-to-set-fixed-window-size-for-universal-windows-application

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