When selecting a node in a tree view with a horizontal scrollbar, it always seems it adjusts this scrollbar to the level of indentation of the selected node, even when the node was already fully visible. This makes for a rather annoying motions where all tree view items are constantly moving around unnecessarily.
To Reproduce
Create a new Avalonia project with a treeview and add some random nodes to them. Example project files below:
MainWindow.axaml:
```xml
```
MainWindow.axaml.cs:
```csharp
using Avalonia.Controls;
namespace AvaloniaTreeViewTest;
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
for (int i = 0; i < 10; i++)
MainTreeView.Items.Add(CreateRandomNode(i, 0));
}
private TreeViewItem CreateRandomNode(int index, int depth)
{
var result = new TreeViewItem();
result.Header = new string((char) ('A' + index), (index + 1) * 5);
if (depth < 4)
{
for (int i = 0; i < 10; i++)
result.Items.Add(CreateRandomNode(i, depth + 1));
}
return result;
}
}
```
Adjust the tree view width or expand some of the tree nodes such that a horizontal scrollbar appears.
Put the horizontal scrollbar back at position 0
Click one of the already fully visible nodes.
Observe the horizontal scrollbar adjusts even though the node was already fully visible.
The tree view should be more conservative with actually adjusting the scroll bars, by only adjusting it when the node is not already (fully) visible.
Avalonia version
11.0.10
OS
Windows, Linux
Additional context
Consider the case where the tree view is used for visualizing a folder structure, and a user wants to quickly browse through the folders to find a file they are looking for. Having the tree view then jump around unnecessarily a lot makes for a rather bad user experience, especially when there are a lot of items in the tree view.
I could disable the auto scrolling by setting AutoScrollToSelectedItem to False, but this is not a great solution. Especially when trying to programmatically set the selected item (think of a folder being opened in the right pane of the demo window), I would want the selected tree view item to be highlighted and visible.
Describe the bug
When selecting a node in a tree view with a horizontal scrollbar, it always seems it adjusts this scrollbar to the level of indentation of the selected node, even when the node was already fully visible. This makes for a rather annoying motions where all tree view items are constantly moving around unnecessarily.
To Reproduce
Create a new Avalonia project with a treeview and add some random nodes to them. Example project files below:
MainWindow.axaml:
```xmlMainWindow.axaml.cs:
```csharp using Avalonia.Controls; namespace AvaloniaTreeViewTest; public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); for (int i = 0; i < 10; i++) MainTreeView.Items.Add(CreateRandomNode(i, 0)); } private TreeViewItem CreateRandomNode(int index, int depth) { var result = new TreeViewItem(); result.Header = new string((char) ('A' + index), (index + 1) * 5); if (depth < 4) { for (int i = 0; i < 10; i++) result.Items.Add(CreateRandomNode(i, depth + 1)); } return result; } } ```Demo video:
https://github.com/AvaloniaUI/Avalonia/assets/3613449/62b6ad98-25b1-4524-8a47-5326119dd776
Expected behavior
The tree view should be more conservative with actually adjusting the scroll bars, by only adjusting it when the node is not already (fully) visible.
Avalonia version
11.0.10
OS
Windows, Linux
Additional context
Consider the case where the tree view is used for visualizing a folder structure, and a user wants to quickly browse through the folders to find a file they are looking for. Having the tree view then jump around unnecessarily a lot makes for a rather bad user experience, especially when there are a lot of items in the tree view.
I could disable the auto scrolling by setting
AutoScrollToSelectedItem
toFalse
, but this is not a great solution. Especially when trying to programmatically set the selected item (think of a folder being opened in the right pane of the demo window), I would want the selected tree view item to be highlighted and visible.