Struggling with udlist(item) and onclick data (eventdata)

Product: PowerShell Universal
Version: 2.5.4

Im trying to get the label name of the clicked listitem using eventdata in the onclick event for new-udlistitem, but it seems it cannot be used/ is empty. Is there another variable that this info gets stored?

i basically want to set a session variable to the name of the label for later use, but i cannot do something like $session:clickedlabe = $_.Task within the onclick, as it is not available there.

Wanted to use get-udelement but not sure how.

$Navigation = {

New-UDList -id task -children {

$RKM | ForEach-Object {

    New-UDListItem -Label "$($_.Task)" -OnClick {

    Show-UDToast -message $EventData

 } }

}

TL;DR : Need to get the label name of the clicked udlistitem somehow, any takers?

This can be from a variable scoping issue with $_

Try this:

New-UDList -id task -children {

$RKM | ForEach-Object {
    $Item = $_
    New-UDListItem -Label "$($_.Task)" -OnClick {

    Show-UDToast -message $Item.Task

 } }

}

OK that was too easy :slight_smile:
Thanks!