Skip to content

Regarding the issue of screen flickering during Refresh when using DataGrid Collections View #204

@Test-HK-BTC

Description

@Test-HK-BTC

Describe the bug

After setting the sorting rules using the DataSGrid Collections View, when the data changes and is reordered for display, there is a flashing screen issue when the mouse hovers over the DataGrid,

Image

The source code is as follows:

.xaml

<DataGrid ItemsSource="{Binding PriceDataView}"  >
	<DataGrid.Styles>
		<Style Selector="DataGridCell TextBlock#CellTextBlock">
			<Setter Property="ToolTip.Tip" Value="{Binding $self.Text}" />
		</Style>
	</DataGrid.Styles>
	<DataGrid.Columns>
             <DataGridTextColumn Header="Content"  Binding="{ReflectionBinding Content}" />
	</DataGrid.Columns>
</DataGrid>

.cs

List<PriceData> Data{ get; } = [];
public DataGridCollectionView PriceDataView{ get; private set; }

var dgsdAscContent = DataGridSortDescription.FromPath("Content", ListSortDirection.Ascending);
PriceDataView = new DataGridCollectionView(Data);
PriceDataView.SortDescriptions.Add(dgsdDescContent);

// Simulate data here at regular intervals
var list = Enumerable.Range(0, Random.Shared.Next(10, 20)).Select(x => new PriceData { Index = x, Content = Random.Shared.Next() }).ToList();
 
var data = Data.ToList();
var indexs = listn.Select(x => x.Index).ToList();
 for (int i = data.Count - 1; i >= 0; i--)
 {
     if (!indexs.Contains(data[i].Index))
     {
         Data.Remove(data[i]);
     }
 }
indexs.Clear();
indexs=null;

 foreach (var item in data) {
     var model = data.FirstOrDefault(x => x.Index == item.Index );
     if (model == null)
     {
         Data.Add(new PriceData  { Index= item.Index, Content = item.Content });
     }
     else
     {
         model.Content = item.Content;
     }
 }

 Dispatcher.UIThread.Invoke(PriceDataView.Refresh);
 data = null;

Expected behavior

The GridGrid Row should be adjusted in order and change values based on the data provided by PriceDataView. The object selected by the mouse should not be changed, and the number of lines the mouse hovers on should not be changed.

Avalonia version

11.3.8

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions