Example #1
0
        void Create()
        {
            var table = new TableLayout();

            table.Spacing = new Size(Spacing, Spacing);

            bool filled = false;
            Action <StackLayoutItem> itemAdding = UpdateLabelItem;
            var expandItem = new StackLayoutItem {
                Expand = true
            };

            switch (Orientation)
            {
            case Orientation.Horizontal:
                var topRow = new TableRow();
                for (int i = 0; i < items.Count; i++)
                {
                    var item = items[i] ?? expandItem;
                    itemAdding(item);
                    var control = item.Control;
                    filled |= item.Expand;
                    var cell = new TableCell {
                        ScaleWidth = item.Expand
                    };
                    switch (item.VerticalAlignment ?? VerticalContentAlignment)
                    {
                    case VerticalAlignment.Top:
                        cell.Control = new TableLayout(control, null);
                        break;

                    case VerticalAlignment.Center:
                        cell.Control = new TableLayout(null, control, null);
                        break;

                    case VerticalAlignment.Bottom:
                        cell.Control = new TableLayout(null, control);
                        break;

                    case VerticalAlignment.Stretch:
                        cell.Control = control;
                        break;

                    default:
                        throw new ArgumentOutOfRangeException();
                    }
                    topRow.Cells.Add(cell);
                }
                if (!filled)
                {
                    topRow.Cells.Add(null);
                }
                table.Rows.Add(topRow);
                break;

            case Orientation.Vertical:
                for (int i = 0; i < items.Count; i++)
                {
                    var item = items[i] ?? expandItem;
                    itemAdding(item);
                    var control = item.Control;
                    filled |= item.Expand;
                    var vrow = new TableRow {
                        ScaleHeight = item.Expand
                    };
                    switch (item.HorizontalAlignment ?? HorizontalContentAlignment)
                    {
                    case HorizontalAlignment.Left:
                        vrow.Cells.Add(TableLayout.Horizontal(control, null));
                        break;

                    case HorizontalAlignment.Center:
                        vrow.Cells.Add(TableLayout.Horizontal(null, control, null));
                        break;

                    case HorizontalAlignment.Right:
                        vrow.Cells.Add(TableLayout.Horizontal(null, control));
                        break;

                    case HorizontalAlignment.Stretch:
                        vrow.Cells.Add(control);
                        break;

                    default:
                        throw new ArgumentOutOfRangeException();
                    }
                    table.Rows.Add(vrow);
                }
                if (!filled)
                {
                    table.Rows.Add(null);
                }
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
            Content   = table;
            isCreated = true;
        }