0

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:

enter image description here

How do you access the fields? As in how could I do something like:

var FieldIWantToUse = selectedItemsDetails.ShortDescription

Thanks guys.

2 Answers 2

3
var FieldIWantToUse = ((RackProduct)selectedItemsDetails.selectedItems).ShortDescription;

Or

var FieldIWantToUse = selectedItemsDetails.selectedItems.ShortDescription;

Is it working?

Sign up to request clarification or add additional context in comments.

Comments

2

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;
        ...
    }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.