Click here to Skip to main content
15,889,992 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi people!!

i wanna do a if statement to check if the image source of a certain image is the same as one string.

I have tried the following methods:
C#
if (image6.Source.ToString() != "/2ND%20EAR;component/Images/add.jpg")

Uri uri = new Uri("/2ND%20EAR;component/Images/add.jpg", UriKind.Absolute);
            ImageSource imgSource = new BitmapImage(uri);
            if (image5.Source.Equals(imgSource))

But both dont work for me.
Does anyone got any other method??

Thanks!
Posted
Updated 17-Apr-12 2:14am
v2
Comments
ZurdoDev 17-Apr-12 8:11am    
Just put breakpoints and see what image6.Source is. This doesn't seem like it should be hard.
xbolslock 17-Apr-12 8:17am    
ya i know. i tried. but it gives me {System.Windows.Media.Imaging.BitmapImage}. thats the troubling part.
ZurdoDev 17-Apr-12 8:24am    
http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.bitmapimage.aspx

To get the "String" of the Uri of the ImageSource, just call .ToString().

So, to be perfectly paranoid, to compare the Uri of two ImageSource objects would be like this:

C#
if (0 == String.Compare(
        imageSource1.ToString(),
        imageSource2.ToString(),
        StringComparison.OrdinalIgnoreCase))
{
    ...
}
 
Share this answer
 
v2
Comments
fjdiewornncalwe 11-Dec-12 11:34am    
Please don't answer old questions like this. It is unlikely that the OP is still looking for an answer to this.
Adam R Harris 11-Dec-12 12:12pm    
True, however if someone else is having the problem his solution just might help.
fjdiewornncalwe 11-Dec-12 17:19pm    
If there were no appropriate answer there already, I'd agree, but when questions are 6+ months old and have answers, then a new answer does nothing more than bump it back up.
Jesse Chisholm 14-Dec-12 10:37am    
I chose to post to this old question (and yes, I knew it was an old question) because I felt that the original answer did not properly address the actual question. My answer allows for comparison to a "String" which is what was asked.
Adarsh Gumashta 5-May-14 6:54am    
Thanks @jesse :) :) .. it was really helpful :)
Off the top of my head, I would think that you should be able to use UriSource to retrieve the source Uri and compare this.
 
Share this answer
 
Comments
xbolslock 17-Apr-12 8:54am    
how do i go around doing that? image5.urisource?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900