Avalonia.Controls.TreeDataGrid
Avalonia.Controls.TreeDataGrid copied to clipboard
Replacing source in TreeDataGrid makes UI blank
Adding new data source to an initialized TreeDataGrid makes it completely blank. The data only becomes visible after a short scrolling. Calling treeDataGrid.InvalidateVisual() doesn't help.
https://user-images.githubusercontent.com/618115/151990475-b4b5e13d-5339-40de-9889-ba086bed6796.mov
Steps to reproduce:
.xaml
<Window xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="AvaloniaTest.MainWindow"
Title="AvaloniaTest">
<DockPanel>
<Button DockPanel.Dock="Bottom" Click="PopulateClick">Populate</Button>
<TreeDataGrid Name="treeDataGrid"/>
</DockPanel>
</Window>
.cs
using System;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.Models.TreeDataGrid;
using Avalonia.Interactivity;
using Avalonia.Markup.Xaml;
namespace AvaloniaTest;
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
#if DEBUG
this.AttachDevTools();
#endif
}
private void InitializeComponent()
{
AvaloniaXamlLoader.Load(this);
}
public void PopulateClick(object sender, RoutedEventArgs e)
{
var treeDataGrid = this.FindControl<TreeDataGrid>("treeDataGrid");
var rootCount = 100;
var items = new Item[rootCount];
for (var i = 0; i < rootCount; i += 1)
{
items[i] = new Item($"Item {i} {DateTime.UtcNow.Ticks}", null);
}
var source = new HierarchicalTreeDataGridSource<Item>(items)
{
Columns =
{
new HierarchicalExpanderColumn<Item>(
new TextColumn<Item, string>(
"Title",
x => x.Title,
new GridLength(1, GridUnitType.Star)
),
x => x.Children,
x => x.Children != null
)
}
};
treeDataGrid.Source = source;
}
}
public class Item
{
public Item[]? Children { get; }
public string Title { get; }
public Item(string title, Item[]? children = null)
{
Title = title;
Children = children;
}
}
Unable to repro this in the same way as you're seeing it, though I do see that the grid isn't laid out properly when pressing "Populate" multiple times.
I confirm what you say. On the latest version items don't disappear anymore, but the layout gets horizontally trimmed.