Exemple #1
0
        protected override void RememberOriginalSize()
        {
            RowDefinition r1 = (RowDefinition)firstRow.Component;
            RowDefinition r2 = (RowDefinition)secondRow.Component;

            original1          = (GridLength)r1.GetValue(RowDefinition.HeightProperty);
            original2          = (GridLength)r2.GetValue(RowDefinition.HeightProperty);
            originalPixelSize1 = r1.ActualHeight;
            originalPixelSize2 = r2.ActualHeight;
        }
Exemple #2
0
        protected override void OnRender(DrawingContext drawingContext)
        {
            base.OnRender(drawingContext);

            if (orientation == Orientation.Horizontal)
            {
                Rect bgRect = new Rect(0, 0, grid.ActualWidth, RailSize);
                drawingContext.DrawRectangle(bgBrush, null, bgRect);

                DesignItemProperty colCollection = gridItem.Properties["ColumnDefinitions"];
                foreach (var colItem in colCollection.CollectionElements)
                {
                    ColumnDefinition column = colItem.Component as ColumnDefinition;
                    if (column.ActualWidth < 0)
                    {
                        continue;
                    }
                    GridLength len = (GridLength)column.GetValue(ColumnDefinition.WidthProperty);

                    FormattedText text = new FormattedText(GridLengthToText(len), CultureInfo.CurrentCulture,
                                                           FlowDirection.LeftToRight, new Typeface("Sergio UI"), 10, Brushes.Black);
                    text.TextAlignment = TextAlignment.Center;
                    drawingContext.DrawText(text, new Point(column.Offset + column.ActualWidth / 2, 0));
                }
            }
            else
            {
                Rect bgRect = new Rect(0, 0, RailSize, grid.ActualHeight);
                drawingContext.DrawRectangle(bgBrush, null, bgRect);

                DesignItemProperty rowCollection = gridItem.Properties["RowDefinitions"];
                foreach (var rowItem in rowCollection.CollectionElements)
                {
                    RowDefinition row = rowItem.Component as RowDefinition;
                    if (row.ActualHeight < 0)
                    {
                        continue;
                    }
                    GridLength len = (GridLength)row.GetValue(RowDefinition.HeightProperty);

                    FormattedText text = new FormattedText(GridLengthToText(len), CultureInfo.CurrentCulture,
                                                           FlowDirection.LeftToRight, new Typeface("Sergio UI"), 10, Brushes.Black);
                    text.TextAlignment = TextAlignment.Center;
                    drawingContext.PushTransform(new RotateTransform(-90));
                    drawingContext.DrawText(text, new Point((row.Offset + row.ActualHeight / 2) * -1, 0));
                    drawingContext.Pop();
                }
            }
        }
 /// <summary>
 /// Gets the AutoLayout Attached Property Value. Used internally to track items which need to be arranged vs. fixed in place.
 /// </summary>
 /// <param name="element"><see cref="RowDefinition"/></param>
 /// <returns>A true value indicates this item should be automatically arranged.</returns>
 internal static bool?GetAutoLayout(RowDefinition element)
 {
     return((bool?)element.GetValue(AutoLayoutProperty));
 }
Exemple #4
0
        protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
        {
            base.OnMouseLeftButtonDown(e);
            e.Handled = true;
            Focus();
            adornerPanel.Children.Remove(previewAdorner);
            if (orientation == Orientation.Vertical)
            {
                double             insertionPosition = e.GetPosition(this).Y;
                DesignItemProperty rowCollection     = gridItem.Properties["RowDefinitions"];

                DesignItem currentRow = null;

                using (ChangeGroup changeGroup = gridItem.OpenGroup("Split grid row")) {
                    if (rowCollection.CollectionElements.Count == 0)
                    {
                        DesignItem firstRow = gridItem.Services.Component.RegisterComponentForDesigner(new RowDefinition());
                        rowCollection.CollectionElements.Add(firstRow);
                        grid.UpdateLayout();                         // let WPF assign firstRow.ActualHeight

                        currentRow = firstRow;
                    }
                    else
                    {
                        RowDefinition current = grid.RowDefinitions
                                                .FirstOrDefault(r => insertionPosition >= r.Offset &&
                                                                insertionPosition <= (r.Offset + r.ActualHeight));
                        if (current != null)
                        {
                            currentRow = gridItem.Services.Component.GetDesignItem(current);
                        }
                    }

                    if (currentRow == null)
                    {
                        currentRow = gridItem.Services.Component.GetDesignItem(grid.RowDefinitions.Last());
                    }

                    unitSelector.SelectedItem = currentRow;
                    for (int i = 0; i < grid.RowDefinitions.Count; i++)
                    {
                        RowDefinition row = grid.RowDefinitions[i];
                        if (row.Offset > insertionPosition)
                        {
                            continue;
                        }
                        if (row.Offset + row.ActualHeight < insertionPosition)
                        {
                            continue;
                        }

                        // split row
                        GridLength oldLength = (GridLength)row.GetValue(RowDefinition.HeightProperty);
                        GridLength newLength1, newLength2;
                        SplitLength(oldLength, insertionPosition - row.Offset, row.ActualHeight, out newLength1, out newLength2);
                        DesignItem newRowDefinition = gridItem.Services.Component.RegisterComponentForDesigner(new RowDefinition());
                        rowCollection.CollectionElements.Insert(i + 1, newRowDefinition);
                        rowCollection.CollectionElements[i].Properties[RowDefinition.HeightProperty].SetValue(newLength1);
                        newRowDefinition.Properties[RowDefinition.HeightProperty].SetValue(newLength2);
                        grid.UpdateLayout();
                        FixIndicesAfterSplit(i, Grid.RowProperty, Grid.RowSpanProperty, insertionPosition);
                        grid.UpdateLayout();
                        changeGroup.Commit();
                        break;
                    }
                }
            }
            else
            {
                double             insertionPosition = e.GetPosition(this).X;
                DesignItemProperty columnCollection  = gridItem.Properties["ColumnDefinitions"];

                DesignItem currentColumn = null;

                using (ChangeGroup changeGroup = gridItem.OpenGroup("Split grid column")) {
                    if (columnCollection.CollectionElements.Count == 0)
                    {
                        DesignItem firstColumn = gridItem.Services.Component.RegisterComponentForDesigner(new ColumnDefinition());
                        columnCollection.CollectionElements.Add(firstColumn);
                        grid.UpdateLayout();                         // let WPF assign firstColumn.ActualWidth

                        currentColumn = firstColumn;
                    }
                    else
                    {
                        ColumnDefinition current = grid.ColumnDefinitions
                                                   .FirstOrDefault(r => insertionPosition >= r.Offset &&
                                                                   insertionPosition <= (r.Offset + r.ActualWidth));
                        if (current != null)
                        {
                            currentColumn = gridItem.Services.Component.GetDesignItem(current);
                        }
                    }

                    if (currentColumn == null)
                    {
                        currentColumn = gridItem.Services.Component.GetDesignItem(grid.ColumnDefinitions.Last());
                    }

                    unitSelector.SelectedItem = currentColumn;
                    for (int i = 0; i < grid.ColumnDefinitions.Count; i++)
                    {
                        ColumnDefinition column = grid.ColumnDefinitions[i];
                        if (column.Offset > insertionPosition)
                        {
                            continue;
                        }
                        if (column.Offset + column.ActualWidth < insertionPosition)
                        {
                            continue;
                        }

                        // split column
                        GridLength oldLength = (GridLength)column.GetValue(ColumnDefinition.WidthProperty);
                        GridLength newLength1, newLength2;
                        SplitLength(oldLength, insertionPosition - column.Offset, column.ActualWidth, out newLength1, out newLength2);
                        DesignItem newColumnDefinition = gridItem.Services.Component.RegisterComponentForDesigner(new ColumnDefinition());
                        columnCollection.CollectionElements.Insert(i + 1, newColumnDefinition);
                        columnCollection.CollectionElements[i].Properties[ColumnDefinition.WidthProperty].SetValue(newLength1);
                        newColumnDefinition.Properties[ColumnDefinition.WidthProperty].SetValue(newLength2);
                        grid.UpdateLayout();
                        FixIndicesAfterSplit(i, Grid.ColumnProperty, Grid.ColumnSpanProperty, insertionPosition);
                        changeGroup.Commit();
                        grid.UpdateLayout();
                        break;
                    }
                }
            }
            InvalidateVisual();
        }
Exemple #5
0
 public static double GetRowActualHeight(RowDefinition d)
 {
     return((double)d.GetValue(RowActualHeightProperty));
 }
Exemple #6
0
 public static double GetHeight([NotNull] RowDefinition element)
 {
     return((double)element.GetValue(AnimatedRow.HeightProperty));
 }
Exemple #7
0
 public static double GetMultiplier([NotNull] RowDefinition element)
 {
     return((double)element.GetValue(AnimatedRow.MultiplierProperty));
 }
Exemple #8
0
 private static bool IsStarRow(RowDefinition definition)
 {
     return(((GridLength)definition.GetValue(RowDefinition.HeightProperty)).IsStar);
 }
 public static double GetPixelHeight(RowDefinition rowDefinition)
 {
     return((double)rowDefinition.GetValue(PixelHeightProperty));
 }