关于C#:如何在启动时设置Windows位置

How can I set the Windows position on startup

我想将窗口的位置设置在屏幕的右侧,类似于WPF。 UWP中是否可以执行此操作?


在AWP中这是不可能的(至少现在还没有),您可以通过访问ApplicationView类来更改窗口大小或使其全屏显示,但是没有WPF中的此类方法/属性。

在MSDN上也有类似的问题。


是的,有一种方法:)例如,转到您的xaml Windows1.xaml

然后将其放在此处。示例代码

1
2
3
4
5
6
7
8
9
10
 <Window
x:Class="Poultry_Management_System.Window1"      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Login"
Width="450"
WindowStartupLocation="CenterScreen"
WindowStyle="None"
ResizeMode="NoResize"
Topmost="True"
KeyDown="keyDown_form"
Height="200">

如您所见,我的StartupLocation位于中心。