Repository navigation
Labels
area/skia ✏️Categorizes an issue or PR as relevant to Skiaarea/treeview 🌲Categorizes an issue or PR as relevant to the TreeView controldifficulty/challenging 🤯Categorizes an issue for which the difficulty level is reachable with internals understandingkind/bugSomething isn't workingplatform/wasm 🌐Categorizes an issue or PR as relevant to the WebAssembly platformproject/items 🧾Categorizes an issue or PR as relevant to items (ItemsControl, ItemsRepeater, ...)
Description
Current behavior
When we are using TreeView and we want the selected element to start the marked TreeView, the code works for the Windows version but does not work for GTK or Wasm.
GTK.mp4
Expected behavior
The expected hehavior is to start with the SeletedItem marked.
Windows.mp4
How to reproduce it (as minimally and precisely as possible)
Create an new Project With the Uno Wizard. (for me 5.0.17.30)
Selecte the Recommended Version.
Marque MVVM.
Create and TreeView on the Main Page.
<muxc:TreeView ItemsSource="{Binding Elements, Mode=TwoWay}"
SelectedItem="{Binding SelectedElement, Mode=TwoWay}"
SelectionMode="Single">
<muxc:TreeView.ItemTemplate>
<DataTemplate x:DataType="local:ElementItem">
<muxc:TreeViewItem IsSelected="{x:Bind IsSelected}"
ItemsSource="{x:Bind Children}"
Content="{x:Bind Name}"
IsExpanded="True"/>
</DataTemplate>
</muxc:TreeView.ItemTemplate>
</muxc:TreeView>
And add Some information on the MainViewModel (Updating the ProjectName to yours)
using Microsoft.UI.Xaml.Controls.Primitives;
namespace UnoApp145.Presentation;
public partial class MainViewModel : ObservableObject
{
[ObservableProperty]
public List<ElementItem>? _elements;
[ObservableProperty]
public ElementItem? _selectedElement;
private INavigator _navigator;
[ObservableProperty]
private string? name;
public MainViewModel(
IStringLocalizer localizer,
IOptions<AppConfig> appInfo,
INavigator navigator)
{
_navigator = navigator;
Title = "Main";
Title += $" - {localizer["ApplicationName"]}";
Title += $" - {appInfo?.Value?.Environment}";
GoToSecond = new AsyncRelayCommand(GoToSecondView);
Elements = new List<ElementItem>
{
new ElementItem
{
Name = "Element 1",
Children = new List<ElementItem>
{
new ElementItem
{
Name = "SubElement 1.1",
Children = new List<ElementItem>
{
new ElementItem
{
Name = "SubElement 1.1.1 Selected",
IsSelected = true,
Children = new List<ElementItem>
{
new ElementItem
{
Name = "SubElement 1.1.1.1",
Children = new List<ElementItem>
{
new ElementItem
{
Name = "SubElement 1.1.1.1.1"
},
new ElementItem
{
Name = "SubElement 1.1.1.1.2"
}
}
},
new ElementItem
{
Name = "SubElement 1.1.1.2"
}
}
},
new ElementItem
{
Name = "SubElement 1.1.2"
}
}
},
new ElementItem
{
Name = "SubElement 1.2"
}
}
},
new ElementItem
{
Name = "Element 2",
Children = new List<ElementItem>
{
// ...
}
}
};
if (Elements != null && Elements.Count > 0)
{
SelectedElement = Elements[0].Children[0].Children[0];
}
}
public string? Title { get; }
public ICommand GoToSecond { get; }
private async Task GoToSecondView()
{
await _navigator.NavigateViewModelAsync<SecondViewModel>(this, data: new Entity(Name!));
}
}
public partial class ElementItem : ObservableObject
{
[ObservableProperty]
private string _name;
[ObservableProperty]
private bool _isSelected;
[ObservableProperty]
private List<ElementItem>? _children;
}Workaround
None, for now.
Works on UWP/WinUI
Yes
Environment
No response
NuGet package version(s)
Affected platforms
WebAssembly, Android, Skia (GTK on Linux/macOS/Windows)
IDE
No response
IDE version
Microsoft Visual Studio Community 2022 (2) (64-bit) - Current Version 17.8.3
Relevant plugins
none
Anything else we need to know?
Project reference.
Metadata
Metadata
Assignees
Labels
area/skia ✏️Categorizes an issue or PR as relevant to Skiaarea/treeview 🌲Categorizes an issue or PR as relevant to the TreeView controldifficulty/challenging 🤯Categorizes an issue for which the difficulty level is reachable with internals understandingkind/bugSomething isn't workingplatform/wasm 🌐Categorizes an issue or PR as relevant to the WebAssembly platformproject/items 🧾Categorizes an issue or PR as relevant to items (ItemsControl, ItemsRepeater, ...)
Activity
Xiaoy312 commentedon Jan 25, 2024
the initial binding doesnt seem to have worked for TreeView or TreeViewItem
only the later changes from user click are pushed back onto the view-model
[-]TreeView Should start with SelectedItem selected[/-][+]`TreeView` should start with `SelectedItem` selected[/+]Youssef1313 commentedon Feb 1, 2024
The item gets selected then unselected. It's unclear why this happens.
13 remaining items
Youssef1313 commentedon Mar 22, 2024
My last investigation:
Runtime test
Findings
For the above runtime test, this line causes
itemNodeImplNoRef.SelectionStateto change in Uno, but not in WinUI.This line is important, and delaying it simply doesn't work. So, I'm suspecting
TreeViewListto be really relying on some behavior up in the hierarchy that's not aligned in Uno.nickrandolph commentedon Apr 3, 2024
@Xiaoy312 @Youssef1313 @jeromelaban can we get an update on where we're at with this?
jeromelaban commentedon Apr 3, 2024
@nickrandolph still in progress.
Xiaoy312 commentedon Apr 6, 2024
[ios]When_SelectedItem_Expanded(111, False)
callstack
nickrandolph commentedon Apr 8, 2024
@Xiaoy312 are you looking for a response on this?
Xiaoy312 commentedon Apr 8, 2024
not really, at least not yet, though any input is appreciated
it is just a quick note
test(TreeView): Check the selection stays single after realization
test(TreeView): Check the selection stays single after realization
docs(treeview): Mark select-on-load as a deviation
docs(treeview): Mark select-on-load as a deviation
docs(treeview): Mark select-on-load as a deviation