Avalonia.Controls.TreeDataGrid icon indicating copy to clipboard operation
Avalonia.Controls.TreeDataGrid copied to clipboard

Cell shift - bug?

Open dexchix opened this issue 2 years ago • 8 comments

Hi, I found a bug, when you scroll to the end of TreeDataGrid via scrollbar, and then scroll up via the mouse wheel, some of the button cells are shifted to the left, can you explain how to fix this bug?

<DataTemplate x:Key="ButtonCell" DataType="m:FileTree">
						<Button Command="{Binding DataContext.DeliteFile, RelativeSource={RelativeSource AncestorType=TreeDataGrid}}"
								CommandParameter="{Binding Path=DataContext, RelativeSource={RelativeSource Self}}" HorizontalAlignment="Right">
							<Button.Styles>
								<Style Selector="Button">
									<Setter Property="HorizontalAlignment" Value="Center"></Setter>
									<Setter Property="Background" Value="White"></Setter>
									<Setter Property="Height" Value="60"></Setter>
									<Setter Property="Width" Value="140"></Setter>
									<Setter Property="VerticalContentAlignment" Value="Center"></Setter>
									<Setter Property="HorizontalContentAlignment" Value="Center"></Setter>
									<Setter Property="Content" Value="Удалить"></Setter>
									<Setter Property="BorderBrush" Value="Black"></Setter>
									<Setter Property="BorderThickness" Value="2"></Setter>
								</Style>
								<Style Selector="Button:pointerover /template/ ContentPresenter">
									<Setter Property="Background" Value="Gray"></Setter>
									<Setter Property="BorderBrush" Value="Black"></Setter>
									<Setter Property="BorderThickness" Value="2"></Setter>
								</Style>
							</Button.Styles>
						</Button>
					</DataTemplate>

image

dexchix avatar Jun 22 '23 13:06 dexchix

I observe the same issue. And it seems that this occurs especially if there's a lot of data to be loaded, and scrolling-speed is high. If I scroll slowly (e.g. using the arrow-buttons instead of the mouse, or also just slowly with the mouse-wheel), then content is loaded in dynamically fine. But if I scroll "quickly", suddenly the cell within one row get shifted around (same as in the picture above). Also note: I'm using TemplateColumns.

Could it be, that the dynamic reloads due to changed viewport during scrolling is somehow messing up the row presenters?

Would really be great to have this fixed, as it's kind of breaking the usage of TreeDataGrid fully (I'm looking for a workaround...)

CleverSnowy avatar Jul 28 '23 08:07 CleverSnowy

I solved this problem by making 2 columns instead of 4, i.e. 1(1) - 2(2-4) and made a large template for the 2nd column (which replaces 3) and the bug disappeared, this may help you out

dexchix avatar Jul 28 '23 08:07 dexchix

Nice one! Yes, that works. Not ideal, but it's a working workaround ;) Thanks!

CleverSnowy avatar Jul 28 '23 09:07 CleverSnowy

I've got the same Issue when used this template:

<TreeDataGrid Source="{Binding Source}" ShowColumnHeaders="False">
  <TreeDataGrid.Resources>

    <DataTemplate x:Key="Names">
      <ContentPresenter Content={Binding}>
        <ContentPresenter.DataTemplates>

          <DataTemplate DataType="{x:Type vm:ClassA}">
            <TextBlock Text="{Binding Name}"/>
          </DataTemplate>

          <DataTemplate DataType="{x:Type vm:ClassB}">
            <TextBlock Text="{Binding Name}"/>
          </DataTemplate>

        </ContentPresenter.DataTemplates>
      </ContentPresenter>
    </DataTemplate>
  </TreeDataGrid.Resources>
</TreeDataGrid>

I want to use this control as virtualized TreeView.

moskalevkn17 avatar Sep 01 '23 05:09 moskalevkn17

Can you try with latest changes on master?. There are some new fixes that probably fix this issue.

danipen avatar Sep 01 '23 06:09 danipen

Can you try with latest changes on master?. There are some new fixes that probably fix this issue.

It doesn't seem to resolve my issue. Example to reproduce this bug: https://github.com/moskalevkn17/AvaloniaTreeDataGridBug/tree/bugExample

I added a new tab "Diffs" in TreeDataGridDemo. If you scroll through an items quickly, you will see that they are randomly mixing.

moskalevkn17 avatar Sep 04 '23 03:09 moskalevkn17

If I change ContentPresenter with ContentControl then bug will disappear.

moskalevkn17 avatar Nov 15 '23 08:11 moskalevkn17

The bug is still here and it is easily reproducible in the Sample App from this repo. Just download it, compile it, and run it without any modifications except updating Nuget packages to the latest versions (this step is optional). Switch to the Wikipedia tab, wait for the content to be completely loaded, then scroll the content up and down by pressing the Up and Down arrows. After several iterations, you'll see the following (see the screenshot).

The bug is reproducible in Mac OS and Windows. In addition to the entries shifted you can notice artifacts from the selection which don't disappear. There's no actual selection on the screenshot, everything is an artifact.

The screenshot

windracer avatar Jan 12 '24 19:01 windracer