Пример #1
0
        static void OnCellPaddingChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs eventArgs)
        {
            CustomGrid grid = (dependencyObject as CustomGrid);

            foreach (UIElement uiElement in grid.Children)
            {
                ApplyMargin(grid, uiElement);
            }
        }
Пример #2
0
        public static void ApplyMargin(CustomGrid PaddingGrid, UIElement element)
        {
            FrameworkElement childElement = element as FrameworkElement;
            Thickness        cellPadding  = PaddingGrid.CellPadding;

            CustomGrid childPaddingGrid = element as CustomGrid;

            if (childPaddingGrid != null)
            {
                // 자식 노드가 PaddingGrid인 경우에는,
                // Margin 이 아닌 CellPadding을 설정한다.
                childPaddingGrid.CellPadding = cellPadding;
            }
            else
            {
                if (childElement != null)
                {
                    // 일반 자식 노드는 Margin을 설정
                    childElement.Margin = cellPadding;
                }
            }
        }
Пример #3
0
        /// <summary>
        /// Border를 그리기 위한 OnRender 재정의
        /// </summary>
        /// <param name="dc"></param>
        protected override void OnRender(System.Windows.Media.DrawingContext dc)
        {
            base.OnRender(dc);

            CustomGrid customGrid = this.Parent as CustomGrid;

            if (customGrid == null)
            {
                dc.DrawRectangle(null, line, new Rect(0, 0, this.ActualWidth, this.ActualHeight));
            }

            double linePoint = 0;
            double posFrom   = 0.0;
            double posTo     = 0.0;

            int rowCount    = Math.Max(this.RowDefinitions.Count, 1);
            int columnCount = Math.Max(this.ColumnDefinitions.Count, 1);

            bool[,] rowCellStatus;
            bool[,] columnCellStatus;

            GetRowLineCellStatus(rowCount, columnCount, out rowCellStatus, out columnCellStatus);

            if (this.ColumnDefinitions.Count != 0)
            {
                for (int row = 0; row < rowCount - 1; row++)
                {
                    var r = this.RowDefinitions[row];

                    linePoint += r.ActualHeight;
                    for (int column = 0; column < columnCount; column++)
                    {
                        bool drawLine = rowCellStatus[row + 1, column];
                        posTo += this.ColumnDefinitions[column].ActualWidth;

                        if (drawLine == true)
                        {
                            dc.DrawLine(line, new System.Windows.Point(posFrom, linePoint), new System.Windows.Point(posTo, linePoint));
                        }

                        posFrom = posTo;
                    }

                    posFrom = 0.0;
                    posTo   = 0.0;
                }
            }

            linePoint = 0;
            posFrom   = 0.0;
            posTo     = 0.0;

            if (this.RowDefinitions.Count != 0)
            {
                for (int column = 0; column < columnCount - 1; column++)
                {
                    var r = this.ColumnDefinitions[column];

                    linePoint += r.ActualWidth;
                    for (int row = 0; row < rowCount; row++)
                    {
                        bool drawLine = columnCellStatus[row, column + 1];
                        posTo += this.RowDefinitions[row].ActualHeight;

                        if (drawLine == true)
                        {
                            dc.DrawLine(line, new System.Windows.Point(linePoint, posFrom), new System.Windows.Point(linePoint, posTo));
                        }

                        posFrom = posTo;
                    }

                    posTo   = 0.0;
                    posFrom = 0.0;
                }
            }
        }