예제 #1
0
        static void ApplyRowPosition(UIElement element)
        {
            int maxRow = 0;

            if (element.INTERNAL_VisualParent != null && element.INTERNAL_VisualParent is Grid) //Note: this also checks if INTERNAL_VisualTreeManager.IsElementInVisualTree(element) is true because there is no point in setting it on Windows and Popups.
            {
                Grid parent = (Grid)element.INTERNAL_VisualParent;
                if (parent._rowDefinitionsOrNull != null && parent._rowDefinitionsOrNull.Count > 0)
                {
                    maxRow = parent._rowDefinitionsOrNull.Count - 1;
                }


                int elementRow = GetRow(element);
                MakeGridPositionCorrect(ref elementRow, maxRow);


                int rowSpan = GetRowSpan(element);
                if (rowSpan <= 1)
                {
                    rowSpan = 1;
                }


                dynamic style    = INTERNAL_HtmlDomManager.GetFrameworkElementBoxSizingStyleForModification(element);
                bool    isMsGrid = Grid_InternalHelpers.isMSGrid();
                if (!isMsGrid)
                {
                    int lastRow = elementRow + rowSpan - 1; //note: there was a -1 here before but it seems to not give he result expected.
                    MakeGridPositionCorrect(ref lastRow, maxRow);


                    style.gridRowStart = (elementRow + 1).ToString(); //Note: +1 because rows start from 1 instead of 0 in js.
                    style.gridRowEnd   = (lastRow + 2).ToString();    //Note: +1 because rows start from 1 instead of 0 in js and another + 1 because the gridRowEnd seems to be the row BEFORE WHITCH the span ends.
                }
                else
                {
                    //probably doesn't work, it probably requires to use msGridRow
                    style.msGridRow     = (elementRow + 1).ToString(); //Note: +1 because rows start from 1 instead of 0 in js.
                    style.msGridRowSpan = (rowSpan).ToString();
                }
            }
        }
        private static void ApplyColumnPosition(UIElement element)
        {
            if (element.IsUnderCustomLayout)
            {
                return;
            }
            int maxColumn = 0;

            if (element.INTERNAL_VisualParent != null && element.INTERNAL_VisualParent is Grid) //Note: this also checks if INTERNAL_VisualTreeManager.IsElementInVisualTree(element) is true because there is no point in setting it on Windows and Popups.
            {
                Grid parent = (Grid)element.INTERNAL_VisualParent;
                if (parent._columnDefinitionsOrNull != null && parent._columnDefinitionsOrNull.Count > 0)
                {
                    maxColumn = parent._columnDefinitionsOrNull.Count - 1;

                    int elementColumn = GetColumn(element);
                    MakeGridPositionCorrect(ref elementColumn, maxColumn);

                    var style      = INTERNAL_HtmlDomManager.GetFrameworkElementBoxSizingStyleForModification(element);
                    int columnSpan = GetColumnSpan(element);
                    if (columnSpan <= 1)
                    {
                        columnSpan = 1;
                    }
                    int lastColumn = elementColumn + columnSpan - 1; //note: there was a -1 here before but it seems to not give he result expected.
                    MakeGridPositionCorrect(ref lastColumn, maxColumn);

                    bool isMsGrid = Grid_InternalHelpers.isMSGrid();
                    if (!isMsGrid)
                    {
                        style.gridColumnStart = (elementColumn + 1).ToString(); //Note: +1 because columns start from 1 instead of 0 in js.
                        style.gridColumnEnd   = (lastColumn + 2).ToString();    //Note: +1 because columns start from 1 instead of 0 in js and another + 1 because the gridColumnEnd seems to be the column BEFORE WHITCH the span ends.
                    }
                    else
                    {
                        style.msGridColumn     = (elementColumn + 1).ToString(); //Note: +1 because columns start from 1 instead of 0 in js.
                        style.msGridColumnSpan = (columnSpan).ToString();        //Note: +1 because columns start from 1 instead of 0 in js and another + 1 because the gridColumnEnd seems to be the column BEFORE WHITCH the span ends.
                    }
                }
            }
        }
예제 #3
0
        internal void LocallyManageChildrenChanged_CSSVersion()
        {
            int maxRow    = 0;
            int maxColumn = 0;

            if (RowDefinitions != null && RowDefinitions.Count > 0)
            {
                maxRow = RowDefinitions.Count - 1;
            }
            if (ColumnDefinitions != null && ColumnDefinitions.Count > 0)
            {
                maxColumn = ColumnDefinitions.Count - 1;
            }

            //UIElement[,] lastElements = new UIElement[maxRow + 1, maxColumn + 1];


            foreach (UIElement uiElement in Children)
            {
                if (INTERNAL_VisualTreeManager.IsElementInVisualTree(uiElement))
                {
                    // Note: the code between here and the "until here" comment can be read as:
                    //  ApplyRowPosition(uiElement);
                    //  ApplyColumnPosition(uiElement);
                    // It has not been implemented that way because this is slightly more efficient and we need elementRow and elementColumn afterwards.
                    int elementRow    = GetRow(uiElement);
                    int elementColumn = GetColumn(uiElement);
                    MakeGridPositionCorrect(ref elementRow, maxRow);
                    MakeGridPositionCorrect(ref elementColumn, maxColumn);

                    int rowSpan = GetRowSpan(uiElement);
                    if (rowSpan < 1)
                    {
                        rowSpan = 1;
                    }
                    int columnSpan = GetColumnSpan(uiElement);
                    if (columnSpan < 1)
                    {
                        columnSpan = 1;
                    }
                    int elementLastRow    = rowSpan + elementRow - 1;
                    int elementLastColumn = columnSpan + elementColumn - 1;
                    MakeGridPositionCorrect(ref elementLastRow, maxRow);
                    MakeGridPositionCorrect(ref elementLastColumn, maxColumn);

                    dynamic style = INTERNAL_HtmlDomManager.GetFrameworkElementBoxSizingStyleForModification(uiElement);

                    style.zIndex   = Canvas.GetZIndex(uiElement).ToString(); // we need this because for some reason, shapes overlap everything in their cell unless everyone has their zIndex set, in which case it depends of the order of the grid's children (which i the normal behaviour).
                    style.position = "relative";

                    bool isMsGrid = Grid_InternalHelpers.isMSGrid();
                    if (!isMsGrid)
                    {
                        style.gridRowStart    = (elementRow + 1).ToString();        //Note: +1 because rows start from 1 instead of 0 in js.
                        style.gridColumnStart = (elementColumn + 1).ToString();     //Note: +1 because rows start from 1 instead of 0 in js.
                        style.gridRowEnd      = (elementLastRow + 2).ToString();    //Note: +1 because rows start from 1 instead of 0 in js and another + 1 because the gridRowEnd seems to be the row BEFORE WHITCH the span ends.
                        style.gridColumnEnd   = (elementLastColumn + 2).ToString(); //Note: +1 because columns start from 1 instead of 0 in js and another + 1 because the gridColumnEnd seems to be the column BEFORE WHITCH the span ends.
                    }
                    else
                    {
                        //probably doesn't work, it probably requires to use msGridRow and msGridColumn and msGridRowSpan and msGridColumnSpan
                        style.msGridRow        = (elementRow + 1).ToString();    //Note: +1 because rows start from 1 instead of 0 in js.
                        style.msGridColumn     = (elementColumn + 1).ToString(); //Note: +1 because rows start from 1 instead of 0 in js.
                        style.msGridRowSpan    = (rowSpan).ToString();           //Note: +1 because rows start from 1 instead of 0 in js and another + 1 because the gridRowEnd seems to be the row BEFORE WHITCH the span ends.
                        style.msGridColumnSpan = (columnSpan).ToString();        //Note: +1 because columns start from 1 instead of 0 in js and another + 1 because the gridColumnEnd seems to be the column BEFORE WHITCH the span ends.
                    }
                    //-------------------------until here-------------------------

                    style.pointerEvents = "none";
                    //style.position = "absolute";
                    //lastElements[elementRow, elementColumn] = uiElement;


                    //---------------------------------------------------------------
                    // Handle the column visibility (mainly changed by the DataGrid)
                    //---------------------------------------------------------------
                    if (Grid_InternalHelpers.IsAllCollapsedColumns(this, elementColumn, elementLastColumn))
                    {
                        CSHTML5.Interop.ExecuteJavaScriptAsync(@"$0.style.overflow = 'hidden'", uiElement.INTERNAL_OuterDomElement);
                        CSHTML5.Interop.ExecuteJavaScriptAsync(@"$0.setAttribute('data-isCollapsedDueToHiddenColumn', true)", uiElement.INTERNAL_OuterDomElement);
                    }
                    else
                    {
                        // Note: we set to Visible only if it was previously Hidden due to the fact that a Grid column is hidden, to avoid conflicts such as replacing the "overflow" property set by the ScrollViewer or by the "ClipToBounds" property.
                        CSHTML5.Interop.ExecuteJavaScriptAsync(@"
if ($0.getAttribute('data-isCollapsedDueToHiddenColumn' == true)){
    $0.style.overflow = 'visible';
    $0.setAttribute('data-isCollapsedDueToHiddenColumn', false);
}", uiElement.INTERNAL_OuterDomElement);
                    }
                }
            }
            //for (int i = 0; i <= maxRow; ++i)
            //{
            //    for (int j = 0; j <= maxColumn; ++j)
            //    {
            //        UIElement uiElement = lastElements[i, j];
            //        if (uiElement != null)
            //        {
            //            dynamic style = INTERNAL_HtmlDomManager.GetFrameworkElementBoxSizingStyleForModification(uiElement);
            //            style.position = "relative";
            //        }
            //    }
            //}
        }