2015-11-12 61 views
1

我目前正在打開一個新的窗口,這樣的:如何層疊新窗口打開的位置?

var v = new View() 
{ 
    Owner = this, 
    WindowStartupLocation = WindowStartupLocation.CenterScreen 
}; 
v.Show(); 

但是,如果用戶試圖打開了多個窗口,他們只是堆疊在彼此的頂部。有沒有什麼明顯的我錯過了級聯他們,讓他們都有點可見?

回答

1

得到它的工作:

var v = new View() 
{ 
    Owner = this 
}; 
var ownedWindows = OwnedWindows.Cast<Window>().Where(w => w.IsVisible).ToList(); 
if (!ownedWindows.Any()) 
{ 
    v.WindowStartupLocation = WindowStartupLocation.CenterScreen; 
} 
else 
{ 
    v.WindowStartupLocation = WindowStartupLocation.Manual; 
    v.Left = ownedWindows.Max(w => w.Left) + 20; 
    v.Top = ownedWindows.Max(w => w.Top) + 20; 
} 
v.Show();