Open SuperJMN opened 1 year ago
+1 Would be a great addition. I am trying to figure out how todo it . So far didn't find any effective way (probably due to my unfamiliarity of this code , hopefully will change in the future :) ).
P.S. Thanks for this great control.
@miryamGSM are we already doing this ourselves in our codebase, right? We maybe can share how we're doing it for reference.
@elix22 Feel free to try my code:
Sample usage here: https://github.com/SuperJMN-Zafiro/Zafiro.Avalonia/blob/ec75ea0defde8ed8d39620ef9ee32dc44842ba21/DataGridSample/Views/MainWindow.axaml#L22
@danipen It would be nice if you can share the code.
@SuperJMN thanks for sharing
I tried it , unfortunately it doesn't work in my case
This one is being called
ScrollToSelectedItemBehavior<T> :OnAttachedToVisualTree()
However when I select one of the items , it doesn't scroll I am going on a short vacation till next week ,once I will be back I will try to debug it .
Thanks
@SuperJMN
It works !!
I had a typo in this line , didn't point to my model , fix it and it works like a charm .
<avalonia:ScrollToSelectedItemBehavior x:TypeArguments="m:DragDropItem">
Thanks alot
@SuperJMN It works !! I had a typo in this line , didn't point to my model , fix it and it works like a charm .
<avalonia:ScrollToSelectedItemBehavior x:TypeArguments="m:DragDropItem">
Thanks alot
That's so nice to hear! Once https://github.com/AvaloniaUI/Avalonia.Controls.TreeDataGrid/pull/134 gets merged, the usage will be quite more straightforward.
@SuperJMN Some feedback It works as expected if only 1 item is selected But won't work for multiple selections , because your code refers only to the first selection (even if there are multiple selections) https://github.com/SuperJMN-Zafiro/Zafiro.Avalonia/blob/master/Zafiro.Avalonia/ScrollToSelectedItemBehavior.cs#L27
So if I will call multiple timessource.RowSelection!.Select(index);
, It will always scroll to the first selection
Well, we basically do the following:
IndexPath
for the node model.RowIndex
using ModelIndexToRowIndex
.BringIntoView
for the RowsPresenter
. var node = /* the model node */;
IndexPath modelIndex = FindModelIndex(_treeDataGrid, node);
int rowIndex = _treeDataGrid.Rows.ModelIndexToRowIndex(modelIndex);
_treeDataGrid.RowsPresenter?.BringIntoView(rowIndex);
@danipen Will you handle ?
Expanding the hierarchy
BringIntoView
implemented by @SuperJMN handles #2
https://github.com/SuperJMN-Zafiro/Zafiro.Avalonia/blob/master/Zafiro.Avalonia/TreeDataGridMixin.cs#L40
Request
Provide a way to bring a given item into view.
Why?
When we need to highlight an item, E. g. a search feature, we'd need to bring the item into view so the user can locate the item easily. This will involve scrolling to the desired item.
This is intrinsically complex due to the nature of the TreeDataGrid which allows hierarchies. Bringing a model into view would imply to know which parents to expand in the hierarchy.
cc @grokys just in case you know an easy way to do this.