/// <summary>
 /// Clears the Collection and creates n amount of new definitions
 /// </summary>
 /// <param name="rows">The collection to refresh</param>
 /// <param name="n">the amount of rows required</param>
 private static void ResetRows(RowDefinitionCollection rows, int n)
 {
     rows.Clear();
     for (int i = 0; i < n; i++)
     {
         rows.Add(new RowDefinition());
     }
 }
 public static void ManiRows(this RowDefinitionCollection rowDef, string format)
 {
     if (rowDef == null)
     {
         throw new NullReferenceException("rowDef nust not be null");
     }
     rowDef.Clear();
     if (string.IsNullOrWhiteSpace(format))
     {
         return;
     }
     string[] value = format.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
     foreach (var item in value)
     {
         if (item.Contains("auto"))
         {
             RowDefinition cd = new RowDefinition()
             {
                 Height = new GridLength(1, GridUnitType.Auto)
             };
             rowDef.Add(cd);
         }
         else if (item.Equals("*"))
         {
             RowDefinition cd = new RowDefinition()
             {
                 Height = new GridLength(1, GridUnitType.Star)
             };
             rowDef.Add(cd);
         }
         else if (item.EndsWith("*"))
         {
             double length;
             if (double.TryParse(item.Substring(0, item.Length - 1), out length))
             {
                 RowDefinition cd = new RowDefinition()
                 {
                     Height = new GridLength(length, GridUnitType.Star)
                 };
                 rowDef.Add(cd);
             }
         }
         else
         {
             RowDefinition cd = new RowDefinition()
             {
                 Height = new GridLength(double.Parse(item))
             };
             rowDef.Add(cd);
         }
     }
 }
        private void ClassChanged(object sender, SelectionChangedEventArgs e)
        {
            try {
                TimeTable timeTable = Connector.GetClassTimeTable(((ComboBox)sender).SelectedItem as Class, StartDate.SelectedDate, EndDate.SelectedDate);
                ClassTimeTable = timeTable;

                ClassGrid.ColumnCount = timeTable.Days;

                int columnCount = timeTable.Days;
                int rowCount    = timeTable.LongestDayMinutes / 5 + 1;

                RowDefinitionCollection rows = ClassGrid.RowDefinitions;
                rows.Clear();
                for (int i = 0; i < rowCount; i++)
                {
                    rows.Add(new RowDefinition());
                }
                Console.WriteLine(rowCount);


                foreach (TimeTableField field in timeTable.Fields)
                {
                    Label lbl = new Label();
                    lbl.Background = Brushes.Red;
                    if (field.Subjects.Length > 0)
                    {
                        int id      = field.Subjects[0].Id;
                        var subject = Connector.Subjects[id];
                        lbl.Content    = subject;
                        lbl.Foreground = new SolidColorBrush(subject.ForegroundColor);
                        lbl.Background = new SolidColorBrush(subject.BackgroundColor);
                    }

                    int column  = (field.StartTime - timeTable.MinDate).Days;
                    int row     = (TimeTable.MinutesOfDay(field.StartTime) - timeTable.EarliestLessonMinute) / 5;
                    int rowSpan = (TimeTable.MinutesOfDay(field.EndTime) - TimeTable.MinutesOfDay(field.StartTime)) / 5;
                    Grid.SetColumn(lbl, column);
                    Grid.SetRow(lbl, row);
                    Grid.SetRowSpan(lbl, rowSpan);
                    ClassGrid.Children.Add(lbl);
                }
            } catch (Exception ex) {
                MessageBox.Show(ex.Message);
            }
        }
Ejemplo n.º 4
0
        private void UpdateLayoutVertical()
        {
            ColumnDefinitionCollection columns = ColumnDefinitions;

            if (columns.Count == 0)
            {
                // For a vertical layout, we have three columns:
                // the Label, LabelSpacing, and the Control

                columns.Add(new ColumnDefinition()
                {
                    Width = new GridLength(0, GridUnitType.Auto)
                });
                columns.Add(new ColumnDefinition()
                {
                    Width = new GridLength(LabelSpacing, GridUnitType.Pixel)
                });
                columns.Add(new ColumnDefinition()
                {
                    Width = new GridLength(1, GridUnitType.Star)
                });
            }

            RowDefinitionCollection rows = RowDefinitions;

            rows.Clear();

            int regularSpacing = Spacing;
            int labelSpacing   = LabelSpacing;

            bool hasStretchingElement = false;

            bool spanColumns     = false;
            bool createNewRow    = true;
            bool addSpacing      = false;
            int  verticalSpacing = regularSpacing;

            HorizontalAlignment labelAlignment = HorizontalAlignment.Left;

            if (LabelAlignment == FormPanelLabelAlignment.Right)
            {
                labelAlignment = HorizontalAlignment.Right;
            }

            for (int i = 0; i < Children.Count; i++)
            {
                FrameworkElement element      = (FrameworkElement)Children[i];
                Label            labelElement = element as Label;

                // Create a new row if we know we need to create one or we
                // encountered a label (even if we weren't expecting one)
                if (createNewRow || ((labelElement != null) && (i != 0)))
                {
                    if (addSpacing && (i != 0))
                    {
                        FormPanelSpacing spacingMode = GetSpacingMode(element);

                        if (spacingMode != FormPanelSpacing.Ignore)
                        {
                            if (spacingMode == FormPanelSpacing.Extra)
                            {
                                verticalSpacing += verticalSpacing;
                            }
                            rows.Add(new RowDefinition()
                            {
                                Height = new GridLength(verticalSpacing, GridUnitType.Pixel)
                            });
                        }
                        addSpacing = false;
                    }
                    rows.Add(new RowDefinition()
                    {
                        Height = new GridLength(0, GridUnitType.Auto)
                    });
                }

                Grid.SetRow(element, rows.Count - 1);

                if (labelElement != null)
                {
                    if (GetLabelPosition(labelElement) == FormPanelLabelPosition.Top)
                    {
                        labelElement.HorizontalAlignment = HorizontalAlignment.Left;
                        Grid.SetColumnSpan(labelElement, 3);

                        spanColumns     = true;
                        createNewRow    = true;
                        verticalSpacing = labelSpacing;
                        addSpacing      = true;
                    }
                    else
                    {
                        labelElement.HorizontalAlignment = labelAlignment;
                        if (labelElement.VerticalAlignment != VerticalAlignment.Top)
                        {
                            labelElement.VerticalAlignment = VerticalAlignment.Center;
                        }

                        spanColumns = false;

                        createNewRow    = false;
                        verticalSpacing = regularSpacing;
                    }
                }
                else
                {
                    if (spanColumns || (GetIsLabeled(element) == false))
                    {
                        Grid.SetColumnSpan(element, 3);
                        spanColumns = false;
                    }
                    else
                    {
                        Grid.SetColumn(element, 2);
                        if (Double.IsNaN(element.Width) == false)
                        {
                            element.HorizontalAlignment = HorizontalAlignment.Left;
                        }
                    }

                    if ((hasStretchingElement == false) && GetIsStretched(element))
                    {
                        rows[rows.Count - 1].Height = new GridLength(1, GridUnitType.Star);
                        hasStretchingElement        = true;
                        element.VerticalAlignment   = VerticalAlignment.Stretch;
                    }
                    else
                    {
                        element.VerticalAlignment = VerticalAlignment.Center;
                    }

                    createNewRow    = true;
                    verticalSpacing = regularSpacing;
                    addSpacing      = true;
                }
            }

            if (hasStretchingElement == false)
            {
                // Add the final filler row
                rows.Add(new RowDefinition()
                {
                    Height = new GridLength(1, GridUnitType.Star)
                });
            }
        }
Ejemplo n.º 5
0
        private void MakeUIStructure()
        {
            //we go through the children and determine the rows, columns and positions in the grid:
            if (this.HasChildren)
            {
                int  amountOfRows    = 1;         // = 1 for the remaining space
                int  amountOfColumns = 1;         // = 1 for the remaining space
                Dock lastChildDock   = Dock.Left; //We only need it to know the amount of rows and columns and to know which row and column are the "remaining space" (sized at star) in the case where LastChildFill is true.

                //first pass: we count the amount of rows and columns.
                foreach (UIElement child in Children)
                {
                    //get the Dock value of the child:
                    Dock dock = DockPanel.GetDock(child);

                    if (dock == Dock.Left || dock == Dock.Right)
                    {
                        ++amountOfColumns;
                    }
                    else
                    {
                        ++amountOfRows;
                    }
                }
                if (LastChildFill) //if the last child fills the remaining space, we "remove" the row/column we "added" for this child.
                {
                    lastChildDock = GetDock(Children[Children.Count - 1]);
                    if (lastChildDock == Dock.Right || lastChildDock == Dock.Left)
                    {
                        --amountOfColumns;
                    }
                    else
                    {
                        --amountOfRows;
                    }
                }

                //second pass: we determine the Grid.Row, Grid.Column, Grid.RowSpan and Grid.ColumnsSpan for each child.
                int amountOfRightPlaced  = 0;
                int amountOfLeftPlaced   = 0;
                int amountOfTopPlaced    = 0;
                int amountOfBottomPlaced = 0;

                foreach (UIElement child in Children)
                {
                    //get the Dock value of the child:
                    Dock dock = DockPanel.GetDock(child);

                    switch (dock)
                    {
                    case Dock.Left:
                        Grid.SetRow(child, amountOfTopPlaced);
                        Grid.SetColumn(child, amountOfLeftPlaced);
                        Grid.SetRowSpan(child, amountOfRows - amountOfTopPlaced - amountOfBottomPlaced);
                        Grid.SetColumnSpan(child, 1);
                        ++amountOfLeftPlaced;
                        break;

                    case Dock.Top:
                        Grid.SetRow(child, amountOfTopPlaced);
                        Grid.SetColumn(child, amountOfLeftPlaced);
                        Grid.SetRowSpan(child, 1);
                        Grid.SetColumnSpan(child, amountOfColumns - amountOfLeftPlaced - amountOfRightPlaced);
                        ++amountOfTopPlaced;
                        break;

                    case Dock.Right:
                        Grid.SetRow(child, amountOfTopPlaced);
                        Grid.SetColumn(child, amountOfColumns - amountOfRightPlaced - 1);
                        Grid.SetRowSpan(child, amountOfRows - amountOfTopPlaced - amountOfBottomPlaced);
                        Grid.SetColumnSpan(child, 1);
                        ++amountOfRightPlaced;
                        break;

                    case Dock.Bottom:
                        Grid.SetRow(child, amountOfRows - amountOfBottomPlaced - 1);
                        Grid.SetColumn(child, amountOfLeftPlaced);
                        Grid.SetRowSpan(child, 1);
                        Grid.SetColumnSpan(child, amountOfColumns - amountOfLeftPlaced - amountOfRightPlaced);
                        ++amountOfBottomPlaced;
                        break;

                    default:
                        break;
                    }
                }

                //we remove the grid because we will change its structure A LOT, and we want to avoid redrawing everything on each change:
                INTERNAL_VisualTreeManager.DetachVisualChildIfNotNull(_grid, this);

                ColumnDefinitionCollection columnsDefinitions = _grid.ColumnDefinitions;
                columnsDefinitions.Clear();
                for (int i = 0; i < amountOfColumns; ++i)
                {
                    columnsDefinitions.Add(new ColumnDefinition()
                    {
                        Width = GridLength.Auto
                    });
                }
                RowDefinitionCollection rowsDefinitions = _grid.RowDefinitions;
                rowsDefinitions.Clear();
                for (int i = 0; i < amountOfRows; ++i)
                {
                    rowsDefinitions.Add(new RowDefinition()
                    {
                        Height = GridLength.Auto
                    });
                }

                if (!LastChildFill)
                {
                    columnsDefinitions.ElementAt(amountOfLeftPlaced).Width = new GridLength(1, GridUnitType.Star);
                    rowsDefinitions.ElementAt(amountOfTopPlaced).Height    = new GridLength(1, GridUnitType.Star);
                }
                else
                {
                    //the position of the "remaining space" depends on the last child's dock:
                    if (lastChildDock == Dock.Left)
                    {
                        columnsDefinitions.ElementAt(amountOfLeftPlaced - 1).Width = new GridLength(1, GridUnitType.Star); //minus 1 because the column index of the last child placed left is also the column index of the "remaining space".
                    }
                    else
                    {
                        columnsDefinitions.ElementAt(amountOfLeftPlaced).Width = new GridLength(1, GridUnitType.Star);
                    }

                    if (lastChildDock == Dock.Top)
                    {
                        rowsDefinitions.ElementAt(amountOfTopPlaced - 1).Height = new GridLength(1, GridUnitType.Star); //minus 1 because the column index of the last child placed left is also the column index of the "remaining space".
                    }
                    else
                    {
                        rowsDefinitions.ElementAt(amountOfTopPlaced).Height = new GridLength(1, GridUnitType.Star); //minus 1 because the column index of the last child placed left is also the column index of the "remaining space".
                    }
                }
                //the changes on the grid's structure are over so we can put it back.
                INTERNAL_VisualTreeManager.AttachVisualChildIfNotAlreadyAttached(_grid, this);
            }
        }
Ejemplo n.º 6
0
 static void \u202E‪‎‏‭‏​‌‬‪‌‪‍‌‌​‬‌‌‫‬‪‏‍‮([In] RowDefinitionCollection obj0)
 {
     obj0.Clear();
 }
        private void UpdateImageGrid(Size newSize)
        {
            GridLength sideLength;
            int        numCols = 0, numRows = 0;

            if ((bool)OneImageBool)
            {
                sideLength = new GridLength(Math.Min(newSize.Width, newSize.Height));
                numCols    = 1;
                numRows    = 1;
            }
            else
            {
                double targetSideLength = 225;
                numCols = (int)(newSize.Width / targetSideLength);
                if (newSize.Width % targetSideLength > (targetSideLength / 2) || numCols == 0)
                {
                    numCols += 1;
                }
                numRows = (int)(newSize.Height / targetSideLength);
                if (newSize.Height % targetSideLength > (targetSideLength / 2) || numRows == 0)
                {
                    numRows += 1;
                }
                double sideLengthDouble = (double)Math.Min(newSize.Width / numCols, newSize.Height / numRows);
                sideLength = new GridLength(sideLengthDouble);
            }

            // Make sure ImageGrid has the right number of FlipImage children.
            if (numCols * numRows == ImageGrid.Children.Count)
            {
                // This will effect all row and column definitions in the grid.
                ImageGrid.RowDefinitions.FirstOrDefault().Height = sideLength;
                return;
            }
            if (numCols * numRows > ImageGrid.Children.Count)
            {
                while (numCols * numRows > ImageGrid.Children.Count)
                {
                    if (flipImageStorage.Count > 0)
                    {
                        FlipImage addMe = flipImageStorage.Pop();
                        addMe.StartTimer();
                        ImageGrid.Children.Add(addMe);
                        continue;
                    }

                    FlipImage flipImage = new FlipImage();

                    // Force the FlipImages to do initial flip if they're new
                    flipImage.ImageList = this.ImageList;

                    flipImage.SetResourceReference(FlipImage.TransitionTypeProperty, "TransitionType");

                    Binding binding = new Binding
                    {
                        Path           = new PropertyPath("ImageList"),
                        RelativeSource = new RelativeSource(RelativeSourceMode.FindAncestor, typeof(FlipImageGrid), 1)
                    };
                    flipImage.SetBinding(FlipImage.ImageListProperty, binding);

                    ImageGrid.Children.Add(flipImage);
                }
            }
            if (numCols * numRows < ImageGrid.Children.Count)
            {
                while (numCols * numRows < ImageGrid.Children.Count)
                {
                    FlipImage toStore = ImageGrid.Children[ImageGrid.Children.Count - 1] as FlipImage;
                    ImageGrid.Children.RemoveAt(ImageGrid.Children.Count - 1);
                    toStore.StopTimer();
                    flipImageStorage.Push(toStore);
                }
            }

            // Ensure proper number of ColumnDefinitions and RowDefinitions.
            ColumnDefinitionCollection colDefs = ImageGrid.ColumnDefinitions;
            RowDefinitionCollection    rowDefs = ImageGrid.RowDefinitions;

            colDefs.Clear(); rowDefs.Clear();
            for (int x = 0; x < numCols; x++)
            {
                for (int y = 0; y < numRows; y++)
                {
                    if (y == 0)
                    {
                        colDefs.Add(new ColumnDefinition()
                        {
                            Width = sideLength, SharedSizeGroup = "FlipImageSharedSizeGroup"
                        });
                    }
                    if (x == 0)
                    {
                        rowDefs.Add(new RowDefinition()
                        {
                            Height = sideLength, SharedSizeGroup = "FlipImageSharedSizeGroup"
                        });
                    }
                }
            }

            // Set grid coordinates of each child in ImageGrid
            int count = 0;

            foreach (FlipImage flipImage in ImageGrid.Children)
            {
                Grid.SetColumn(flipImage, count % numCols);
                Grid.SetRow(flipImage, count / numCols);
                count++;
            }
        }
Ejemplo n.º 8
0
        protected override Size MeasureOverride(Size constraint)
        {
            UIElementCollection     children = Children;
            RowDefinitionCollection rowDefs  = RowDefinitions;
            int chCount = children.Count;
            int rdCount = rowDefs.Count;

            if (rdCount < chCount)
            {
                int d  = chCount - rdCount;
                int ix = chCount - d;

                for (int i = 0; i < d; i++)
                {
                    rowDefs.Add(new RowDefinition()
                    {
                        Height    = new GridLength(100.0, GridUnitType.Star),
                        MinHeight = MinRowHeight
                    });
                    //SetRow(children[ix], ix);
                    //ix++;
                }

                for (int i = 0; i < chCount; i++)
                {
                    SetRow(children[i], i);
                }
            }
            else if (rdCount > chCount)
            {
                int chIx = chCount - 1;

                if (chIx < 0)
                {
                    rowDefs.Clear();
                }
                else
                {
                    for (int i = rdCount - 1; i >= 0; i--)
                    {
                        if (chIx < 0)
                        {
                            rowDefs.RemoveAt(i);
                            continue;
                        }

                        int row = GetRow(children[chIx]);
                        if (row != i)
                        {
                            rowDefs.RemoveAt(i);
                            continue;
                        }

                        chIx--;
                    }

                    for (int i = 0; i < chCount; i++)
                    {
                        int row = GetRow(children[i]);
                        if (row != i)
                        {
                            SetRow(children[i], i);
                        }
                    }
                }
            }
            else
            {
                for (int i = 0; i < chCount; i++)
                {
                    int row = GetRow(children[i]);
                    if (row != i)
                    {
                        SetRow(children[i], i);
                    }
                }
            }

            return(base.MeasureOverride(constraint));
        }