2009-10-09 119 views
29

我想在屏幕右上角打開一個WPF窗口。更改WPF窗口的啓動位置

現在我可以通過打開窗口然後移動它(通過user32.dll中的移動窗口)來實現。但是,這種方法意味着窗口打開它的默認位置,完全加載,然後移動到右上角。

我該如何改變它,以便我可以指定窗口的初始位置和大小?

回答

76

只需設置WindowStartupLocation,高度,寬度,左和頂在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> 
+0

謝謝!我知道它必須很簡單,但我試圖找到複雜的解決方案:)。 – Evan 2009-10-09 18:12:33

+0

太棒了!這就是我在尋找'win.WindowStartupLocation ='[WindowStartupLocation](https://msdn.microsoft.com/en-us/library/system.windows.windowstartuplocation(v = vs.110).aspx)''。中心屏幕;' – marbel82 2016-11-29 15:04:30