小编Myo*_*tis的帖子

如何在通用应用程序中设置窗口大小?

我使用C#和XAML,我的主页开头如下:

<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>
Run Code Online (Sandbox Code Playgroud)

但是当我启动应用程序时,窗口总是最大化.只有网格尊重XAML中提到的大小.我在这个论坛上读到了一些答案,但是当我写作时我遇到了编译错误:

ResizeMode="NoResize"
Run Code Online (Sandbox Code Playgroud)

在XAML代码中,或

Application.Current.MainWindow.Height = 754;
Run Code Online (Sandbox Code Playgroud)

在C#代码中(因为Application.Current是已知的,但不是Application.Current.MainWindow).

我无法弄清楚为什么这些解决方案对我不起作用.我也能看到这个:

WindowState="Maximized"
ResizeMode="NoResize"
WindowStyle="None"
Run Code Online (Sandbox Code Playgroud)

它也不起作用:"它在上下文中不存在".怎么了 ?

c# xaml uwp windows-10-universal uwp-xaml

2
推荐指数
1
解决办法
1782
查看次数

标签 统计

c# ×1

uwp ×1

uwp-xaml ×1

windows-10-universal ×1

xaml ×1