I'm coding the backend portion of a software and at some point I need my user to choose some things, it can be a convoluted process, the user can even cancel the selection at any point.
From the back end I'd like to do something like:
private async void StartAction()
{
//some code
var SelectedItem = await UI.RequestUserToChooseItem();
// some final code using the selected item
}
Here I don't know how to handle cancellation, but I can send null and assume that if the SelectedItem
is null it was canceled.
But what about the UI portion of it? How do I handle it to return the call when the thing is selected by the user?
I need to perform some steps here: (this is pseudocode, I don't even know where to start)
public List<Item> RequestUserToChooseItem()
{
PrepareItemsInList();
ShowSelectionPanel();
List<Items> SelectedItemsFromPanel = WaitForUserToChose(); //???????
return SelectedItemsFromPanel;
}
And then we have the cancel button:
private void CancelButtonClicked(object sender, EventArgs e)
{
CancelWaitedSelectionProcessAndReturnNull(); //????
}