vendredi 29 mars 2019

Why won't this if statement comparing WPF ImageSources be executed?

I'm checking that an image matches the image source that I want, which will then instantiate a class "Queen". To do this, I am iterating through a list of objects, "nodes", which has a method, getType(), which returns an image. I am checking each of the images in this colony.getNodes() list.

I am 100% sure that at least one of the images matches "H:\Year 13\Computing\Ant Simulation\QueenRoom.png" as I have checked using breakpoints. So why won't it ever enter my if statement.

I have also tried instead of comparing colony.getNodes()[i].getType().Source to a new instance of BitmapImage, creating a BitmapImage variable before the for loop, however this didn't help.

        for (int i = 0; i < colony.getNodes().Count; i++)
        {
            if (colony.getNodes()[i].getType().Source == new BitmapImage(new Uri(@"H:\Year 13\Computing\Ant Simulation\LarvaRoom.png")))
            {
                nurseryFood.Add(colony.getNodes()[i].getLocation(), 0);
            }
            if (colony.getNodes()[i].getType().Source == new BitmapImage(new Uri(@"H:\Year 13\Computing\Ant Simulation\QueenRoom.png")))
            {
                queen = new Queen(colony.getNodes()[i].getLocation(), colony.getNodes()[i].getType().Margin);
            }
        }

I also have another if statement which has exactly the same problem. Testing using breakpoints, the if statements are never entered. How can I make this work?

Aucun commentaire:

Enregistrer un commentaire