Changing the start up location of a WPF window

Evan picture Evan · Oct 9, 2009 · Viewed 77.9k times · Source

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

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?

Answer

Reed Copsey picture Reed Copsey · Oct 9, 2009

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>