Reputation: 301
I have a list of products, sitting in a ListView. Each product has details. If I press a button in one of the products within the ListView, the event handler is bound to the product and all its details. Lets say for arguments sake that the button fires the following event handler:
public async void OnClickViewImageCarousel(object sender, EventArgs e)
{
var selectedItemDetails = ((Button)sender).CommandParameter;
}
During debugging, the selectedItemDetails shows the following locals:
How do you access the fields? As in how could I do something like:
var FieldIWantToUse = selectedItemsDetails.ShortDescription
Thanks guys.
Upvotes: 0
Views: 59
Reputation: 2299
You should use direct casting to the items type from which your listView consists of. A little example (for popup menu but the idea the same):
XAML:
<MenuItem ...Clicked="ButtonClicked" CommandParameter="{Binding .}" />
Code:
private void ButtonClicked(object sender, EventArgs args)
{
var yourVar = (YourType)((MenuItem)sender).CommandParameter;
...
}
Upvotes: 2
Reputation: 71
var FieldIWantToUse = ((RackProduct)selectedItemsDetails.selectedItems).ShortDescription;
Or
var FieldIWantToUse = selectedItemsDetails.selectedItems.ShortDescription;
Is it working?
Upvotes: 3