更改 WPF 窗口的启动位置 [英] Changing the start up location of a WPF window

查看:85
本文介绍了更改 WPF 窗口的启动位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在屏幕的右上角打开一个 WPF 窗口.

I'd like to have a WPF window open in the top right part of the screen.

现在我可以通过打开窗口然后移动它来实现这一点(通过 user32.dll 中的 movewindow).但是,这种方法意味着窗口在其默认位置打开,完全加载,然后移动到右上角.

Right now I can achieve that by opening the window and then moving it (via movewindow in user32.dll). However, this approach means the window opens in it's default location, fully loads, and then moves to the top right.

我该如何更改它以便指定窗口的初始位置和大小?

How could I do I change it so that I could specify the window's initial position and size?

推荐答案

只需在 xaml 中设置 WindowStartupLocation、Height、Width、Left 和 Top:

Just set WindowStartupLocation, Height, Width, Left, and Top in xaml:

<Window x:Class="WpfApplication1.Window1" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    Title="Window1" 
    Height="500" Width="500"
    WindowStartupLocation="Manual" 
    Left="0" Top="0">
</Window>

这篇关于更改 WPF 窗口的启动位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆