Пример #1
0
        void ShowWindowsInDesktop(List <WindowItem> windows, Grid grid, Desktop desktop)
        {
            List <WindowItem> .Enumerator e = windows.GetEnumerator();
            UIElement desktopElement        = desktop.desktopElement;

            double parentWidth  = desktopElement.RenderSize.Width;
            double parentHeight = desktopElement.RenderSize.Height;
            Point  origin       = desktopElement.TransformToAncestor(this).Transform(new Point(0, 0));
            double x            = origin.X;
            double y            = origin.Y;
            // figure out width and height per item
            double widthPerItem  = parentWidth / grid.Width;
            double heightPerItem = parentHeight / grid.Height;


            for (int hi = 0; hi < grid.Height; hi++)
            {
                for (int wi = 0; wi < grid.Width; wi++)
                {
                    if (!e.MoveNext())
                    {
                        e.Dispose();
                        break;
                    }
                    WindowItem entry = e.Current;
                    if (entry == null)
                    {
                        continue;
                    }

                    Console.WriteLine("Window: {0}, in Desktop: {1}", entry.Title, desktop.Id);

                    int startXPos = (int)(wi * widthPerItem + x);
                    int startYPos = (int)(hi * heightPerItem + y);
                    int endXPos   = (int)((wi + 1) * widthPerItem + x);
                    int endYPos   = (int)((hi + 1) * heightPerItem + y);

                    Console.WriteLine("Left: {0}, Top: {1}, Right: {2}, Bottom: {3}", startXPos, startYPos, endXPos, endYPos);

                    entry.SetContainerRect(startXPos, startYPos, endXPos, endYPos);
                    WindowContainer.Children.Add(entry);
                    entry.DrawRectForWindow();
                }
            }
        }