Get a ListBoxItem when clicked.
Hi there, I'm messing around with ListBoxes and am trying to figure out the best way of getting the content of a ListBoxItem when I click it.
Here's what I have currently:
Hopefully you guys understand what I'm asking 
Here's what I have currently:
Code: Select all
public void AddToList()
{
...
_characterList.GetItems().Add(testItem);
testItem.Selected += this.OnSelectedClick;
}
void OnSelectedClick(BaseComponent sender, RoutedEventArgs args)
{
// This is where I can't figure out how to get the clicked ListBoxItem that has been clicked.
}

Re: Get a ListBoxItem when clicked.
Hi,
I'm new to this too but i think it should be this :
I'm new to this too but i think it should be this :
Code: Select all
void OnSelectedClick(BaseComponent sender, RoutedEventArgs args)
{
ListBoxItem listBoxItem = sender.As<ListBoxItem>();
}
Re: Get a ListBoxItem when clicked.
Yes! That worked like a charm, thanks! 
Still figuring this system out a bit, hopefully this thread is helpful to some other dev later on as well
.
Edit:
I wanted to post another little snippet that might help others in need. An alternative way of getting the current selected Item is:
Just as a tip
.

Still figuring this system out a bit, hopefully this thread is helpful to some other dev later on as well

Edit:
I wanted to post another little snippet that might help others in need. An alternative way of getting the current selected Item is:
Code: Select all
ListBoxItem _selectedItem = _YourList.GetSelectedItem().As<ListBoxItem>();

-
-
sfernandez
Site Admin
- Posts: 3197
- Joined:
Re: Get a ListBoxItem when clicked.
Thanks for all the information you are providing. It may be very useful for other users 

-
- jc_lvngstn
- Posts: 34
- Joined:
Re: Get a ListBoxItem when clicked.
Is there a way to get the currently selected items from a listbox, such as
ListBox.SelectedItems
?
It's documented, but doesn't seem to exist.
ListBox.SelectedItems
?
It's documented, but doesn't seem to exist.
-
-
sfernandez
Site Admin
- Posts: 3197
- Joined:
Re: Get a ListBoxItem when clicked.
You are right, that function was not exposed to the Unity API. I've just added so it will be available in the following release due this week.Is there a way to get the currently selected items from a listbox, such as
ListBox.SelectedItems
?
It's documented, but doesn't seem to exist.
Who is online
Users browsing this forum: No registered users and 11 guests