Git Product home page Git Product logo

Comments (9)

Hover233 avatar Hover233 commented on May 29, 2024 2

The sorting operation also triggers this bug, hopefully it will be fixed sooner!
QQ截图20240315104826

from avalonia.controls.treedatagrid.

wieslawsoltes avatar wieslawsoltes commented on May 29, 2024

Repro video:

TreeDataGridDemo_Dop2Rhbv73.mp4

from avalonia.controls.treedatagrid.

artizzq avatar artizzq commented on May 29, 2024

Same issue

from avalonia.controls.treedatagrid.

wieslawsoltes avatar wieslawsoltes commented on May 29, 2024

Tested it can reproed also in 11.0.0 and 11.0.1

from avalonia.controls.treedatagrid.

wieslawsoltes avatar wieslawsoltes commented on May 29, 2024

Tested 11.0.0-preview1 and seems to be working properly

from avalonia.controls.treedatagrid.

wieslawsoltes avatar wieslawsoltes commented on May 29, 2024

Repro branch: https://github.com/AvaloniaUI/Avalonia.Controls.TreeDataGrid/tree/issues-256-repro

from avalonia.controls.treedatagrid.

wieslawsoltes avatar wieslawsoltes commented on May 29, 2024

Seems to be related to this:

// We sometimes get sent a viewport of 0,0 because the EffectiveViewportChanged event
// is being raised when the parent control hasn't yet been arranged. This is a bug in
// Avalonia, but we can work around it by forcing MeasureOverride to estimate the
// viewport.

from avalonia.controls.treedatagrid.

wieslawsoltes avatar wieslawsoltes commented on May 29, 2024

Actually even without min/max width the layout breaks when scrolling.

repro:

                Columns =
                {
                    new TextColumn<Country, string>("Country", x => x.Name, (r, v) => r.Name = v, new GridLength(1, GridUnitType.Star), new()
                    {
                        IsTextSearchEnabled = true,
                    }),
                    new TemplateColumn<Country>("Region", "RegionCell", "RegionEditCell"),
                    new TextColumn<Country, int>("Population", x => x.Population, new GridLength(200, GridUnitType.Auto), new TextColumnOptions<Country>() ),
                    new TextColumn<Country, int>("Area", x => x.Area, new GridLength(200, GridUnitType.Auto), new TextColumnOptions<Country>() ),
                    new TextColumn<Country, int>("GDP", x => x.GDP, new GridLength(200, GridUnitType.Auto), new()
                    {
                        TextAlignment = Avalonia.Media.TextAlignment.Right,
                    }),
                }

screenshots:
image
image

from avalonia.controls.treedatagrid.

artizzq avatar artizzq commented on May 29, 2024

@wieslawsoltes, Isn't it something with the RealizeElements function inside TreeDataGridPresenterBase? Is it really related to viewport?

Seems to be related to this:

// We sometimes get sent a viewport of 0,0 because the EffectiveViewportChanged event
// is being raised when the parent control hasn't yet been arranged. This is a bug in
// Avalonia, but we can work around it by forcing MeasureOverride to estimate the
// viewport.

At least, I've tried to catch those problematic rows, but dont know what to do with them exactly and how to update them properly... Does it make sense?

private void RealizeElements(
    IReadOnlyList<TItem> items,
    Size availableSize,
    ref MeasureViewport viewport)
{
    Debug.Assert(_measureElements is not null);
    Debug.Assert(_realizedElements is not null);
    Debug.Assert(items.Count > 0);

    var index = viewport.anchorIndex;
    var horizontal = Orientation == Orientation.Horizontal;
    var u = viewport.anchorU;

    // If the anchor element is at the beginning of, or before, the start of the viewport
    // then we can recycle all elements before it.
    if (u <= viewport.anchorU)
        _realizedElements.RecycleElementsBefore(viewport.anchorIndex, _recycleElement);

    // Start at the anchor element and move forwards, realizing elements.
    do
    {
        var e = GetOrCreateElement(items, index);
        var constraint = GetInitialConstraint(e, index, availableSize);
        var slot = MeasureElement(index, e, constraint);

        var sizeU = horizontal ? slot.Width : slot.Height;
        var sizeV = horizontal ? slot.Height : slot.Width;

        _measureElements!.Add(index, e, u, sizeU);

        //viewport.measuredV = Math.Max(viewport.measuredV, sizeV);
        if (horizontal == false && items.GetType() == typeof(AnonymousSortableRows<DataRowView>))
        {
            if (sizeV - viewport.measuredV == sizeV)
                viewport.measuredV = Math.Max(viewport.measuredV, sizeV);
            else
            {
                if (viewport.measuredV != sizeV)
                    if (Math.Abs(sizeV - viewport.measuredV) <= 200 || Math.Abs(sizeV - viewport.measuredV) > 200)
                    {
                        if (sizeV > viewport.measuredV)
                        {
                            sizeV = viewport.measuredV;
                            e.Arrange(new Rect(e.Bounds.Left, e.Bounds.Top, viewport.measuredV, sizeU));
                            e.Measure(e.Bounds.Size);
                        } else
                        {
                            viewport.measuredV = sizeV;
                            e.Arrange(new Rect(e.Bounds.Left, e.Bounds.Top, viewport.measuredV, sizeU));
                            e.Measure(e.Bounds.Size);
                        }
                    }
                    else if (viewport.measuredV == sizeV)
                    {

                    }
            }

        }
        else 
            viewport.measuredV = Math.Max(viewport.measuredV, sizeV);

        u += sizeU;
        ++index;
    } while (u < viewport.viewportUEnd && index < items.Count);

    // Store the last index and end U position for the desired size calculation.
    viewport.lastIndex = index - 1;
    viewport.realizedEndU = u;

    // We can now recycle elements after the last element.
    _realizedElements.RecycleElementsAfter(viewport.lastIndex, _recycleElement);

    // Next move backwards from the anchor element, realizing elements.
    index = viewport.anchorIndex - 1;
    u = viewport.anchorU;

    while (u > viewport.viewportUStart && index >= 0)
    {
        var e = GetOrCreateElement(items, index);
        var constraint = GetInitialConstraint(e, index, availableSize);
        var slot = MeasureElement(index, e, constraint);

        var sizeU = horizontal ? slot.Width : slot.Height;
        var sizeV = horizontal ? slot.Height : slot.Width;
        u -= sizeU;

        _measureElements.Add(index, e, u, sizeU);

        //viewport.measuredV = Math.Max(viewport.measuredV, sizeV);
        if (horizontal == false && items.GetType() == typeof(AnonymousSortableRows<DataRowView>))
        {
            if (sizeV - viewport.measuredV == sizeV)
                viewport.measuredV = Math.Max(viewport.measuredV, sizeV);
            else
            {
                if (viewport.measuredV != sizeV)
                    if (Math.Abs(sizeV - viewport.measuredV) <= 200 || Math.Abs(sizeV - viewport.measuredV) > 200)
                    {
                        if (sizeV > viewport.measuredV)
                        {
                            sizeV = viewport.measuredV;
                            e.Arrange(new Rect(e.Bounds.Left, e.Bounds.Top, viewport.measuredV, sizeU));
                            e.Measure(e.Bounds.Size);
                        }
                        else
                        {
                            viewport.measuredV = sizeV;
                            e.Arrange(new Rect(e.Bounds.Left, e.Bounds.Top, viewport.measuredV, sizeU));
                            e.Measure(e.Bounds.Size);
                        }
                    }
                    else if (viewport.measuredV == sizeV)
                    {

                    }
            }

        }
        else
            viewport.measuredV = Math.Max(viewport.measuredV, sizeV);
        --index;
    }

    // We can now recycle elements before the first element.
    _realizedElements.RecycleElementsBefore(index + 1, _recycleElement);
}

Also, I've noticed when columns have equal widths there's no bug at all, and when I change width manually it happens.

from avalonia.controls.treedatagrid.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.