Avalonia ListBox pass selected DataTemplate
I put a behavior under ListBox to respond on the item clicked, is there a way to pass selected list member to VM? The code is in the file here: https://paste.mod.gg/lapcinshlpan/0 (now it passes current one that is set in code)
BlazeBin - lapcinshlpan
A tool for sharing your source code with the world!
13 Replies
Please prefer $paste
If your code is too long, you can post to https://paste.mod.gg/, save, and copy the link into chat for others to see your shared code!
as rarely people download files to actually help.
Got it, thanks!
ListBox | Avalonia Docs
REFERENCE - Built-in Controls
I don't think it helps, I suspect I need to add CommandParameter into InvokeCommandAction, but not sure what to pass there
<ListBox SelectedItem="{MyItem}"> and MyItem can be used in viewmodel
MyItem will be changed after each click
thats what you asked for: * is there a way to pass selected list member to VM?*
I did it, yet still no results
![No description](https://cdn.answeroverflow.com/1265051405702529154/image.png)
I found smth similar in my code
![No description](https://cdn.answeroverflow.com/1265172128395956254/image.png)
but anyway SelectedItem should work
in my case it works well
Okay, I managed to get somewhere with your example. Command and SourceObject was something new to me
It wasn't working at first as my EventName was "SelectionChanged". Changing it to "Tapped" removes errors, but it seems like "Tapped" is for touch screens. Do you know where can I find EventNames as VS doesn't list them for me?
I didn't find smth like enum with all event names but I found this: https://github.com/AvaloniaUI/Avalonia.Xaml.Behaviors/tree/master/src/Avalonia.Xaml.Interactions.Events
GitHub
Avalonia.Xaml.Behaviors/src/Avalonia.Xaml.Interactions.Events at ma...
Port of Windows UWP Xaml Behaviors for Avalonia Xaml. - AvaloniaUI/Avalonia.Xaml.Behaviors