我想水平/垂直平铺所有打开的窗口。 所以我可以一起看到它们。
请帮助我...: - ((
答案 0 :(得分:3)
您必须拥有一个窗口列表才能平铺它们。一种方法是使用静态属性将WeakReferences存储到所有创建的窗口,如下所示:
static List<WeakRef> _registeredWindows;
public void RegisterWindow(Window w)
{
_registeredWindows.Add(new WeakReference(w));
}
现在很容易平铺所有可见的注册窗口:
public void TileRegisteredWindowsHorizontally()
{
// Find visible registered windows in horizontal order
var windows = (
from weak in _registeredWindows
let window = weak.Target as Window
where window!=null && window.Visibility==Visibility.Visible
orderby window.Left + window.Width/2 // Current horizontal center of window
select window
).ToList();
// Get screen size
double screenWidth = SystemParameters.PrimaryScreenWidth;
double screenHeight = SystemParameters.PrimaryScrenHeight;
// Update window positions to tile them
int count = windows.Count();
foreach(int i in Enumerable.Range(0, count))
{
var window = windows[i];
window.Left = i * screenWidth / count;
window.Width = screenWidth / count;
window.Top = 0;
window.Height = screenHeight;
}
}
工作原理:第一个查询扫描WeakRefs以查看可见的实时窗口,并按中心水平对它们进行排序。末端的循环调整窗口位置。