Hi there, trying to do something I thought was pretty basic, but can't get around this error.

I have a ListBox, List (AllImages) full of image paths, and two image elements.

Image 1 displays the selected item, Image 2 displays selected item + 1

I have:
int inx = Convert.ToString(ImageList.SelectedIndex);

to get the current index selection, and then I'm passing that into the List (since the indexes will be the same) with:

Background.Source = new BitmapImage(new Uri((AllImages[inx])));

The erorr I get is: Argument 1: cannot convert from 'method group' to 'int' Image Viewer

Is someone able to help me? When I use numbers 0-9 instead of passing a variable, the output is the full file name of the image, so I can't understand why it won't work with an int variable.

You're taking the selected index converting it to a string then trying to store it as an integer. C# doesn't allow this kind of implicit conversion. What you probably need to do is just store the selected index directly:

int inx = ImageList.SelectedIndex;

Okay, I've changed that line to: int inx = ImageList.SelectedIndex;

I'm still getting the same error "cannot convert from 'method group' to 'int'.

Is there anything else I could try?

It just occured to me that I may be defining the variable inx incorrectly. Is this right?

 private void inx (object sender, RoutedEventArgs e)
            int inx = 0;

SelectedIndex returns an int (see here) so you dont have to do a conversion to a string as Tinstaafl already correctly pointed out.
I don't understand what you mean by
and then I'm passing that into the List (since the indexes will be the same)
Could you clarify?

What I mean is that I'm using the selected index of the ListBox to determine which is the next consecutive index of the AllImages List.

I've managed to sort it now, and it was my declaration of the variable. I'm not sure if what I've done is entirely correct, but I've moved the declaration to App.xaml.cs with the following code:

public partial class App : Application { public static int inx; }

And that works perfectly. Just not sure if it's good practise to declare that variable so globally.

This question has already been answered. Start a new discussion instead.