Hide windows using the Infrastructure dialog box

I am using Infragistics XamDialogWindow to approximate an MDI window in WPF.

Basically, I have a user control that I assign to the contents of the window, and then add XamDialogWindow as a child of the grid.

Then I have two buttons that display the windows as Tile or Cascade.

The cascade works very well, but I'm having problems with the Tile method.

I get the available width and height using the "ActualWidth" and "ActualHeight" properties in the container.

Then I calculate the number of rows and columns required.

Next, I repeat the columns and calculate the number of rows in the column (this means that if there is an odd number of windows like 5, I will have two rows in columns 0 and 3 in column 1).

The width of each window is defined as "AvailableWidth / numColumns"

The height of each window is defined as "AvailableHeight / WindowsForThisColumn"

Then I repeat the lines and calculate the upper left coordinate of the window, which we position as follows:

left = columnIndex * width

top = rowIndex * height

Then the properties Left, Top, Width and Height are set.

PROBLEM

The properties Left, Top, Width and Height seem correctly calculated, for example,

  • AvailableWidth = 1000;
  • AvailableHeight = 1000;
  • Window1 = 0, 0, 500, 500
  • Window2 = 0, 500, 500, 500
  • Window3 = 500, 0.500, 500
  • Window4 = 500, 500, 500, 500

4 , , .

(. ).

Left, Top, Width Height, .

, "" , .

, .

Canvas Canvas.Left Top, , .

- ? , , WPF Render Time

ImagesOffset

 var childrenToArrange = Children.Where(a => a.WindowState != Infragistics.Controls.Interactions.WindowState.Minimized).ToList();

        var availableWidth = Panel.ActualWidth;
        var availableHeight = Panel.ActualHeight;

        if (Layout == MDILayout.TILE)
        {
            //get the number of rows and columns
            int rows = (int)Math.Sqrt(childrenToArrange.Count);
            int columns = childrenToArrange.Count / rows;

            var index = 0;
            var width = availableWidth / columns;

            //iterate through the columns
            for (int x = 0; x < columns; x++)
            {
                //get the number of windows for this column
                var windowsForThisColumn = rows;
                if (childrenToArrange.Count % columns > (columns - x - 1))
                    windowsForThisColumn++;

                var height = availableHeight / windowsForThisColumn;

                //iterate through the rows
                for (int y = 0; y < windowsForThisColumn; y++)
                {
                    //get the X and Y coordinates
                    var left = x * width;
                    var top = y * height;

                    //get the window
                    var mdiChild = childrenToArrange[index] as XamDialogWindow;

                    mdiChild.Margin = new Thickness(0);
                    mdiChild.Left = left;
                    mdiChild.Top = top;
                    mdiChild.Width = width;
                    mdiChild.Height = height;
                    index++;
                }
            }
        }
+6

Source: https://habr.com/ru/post/1017073/


All Articles