Click here to Skip to main content
11,637,176 members (69,978 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: C# Windows Phone
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:
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??

Posted 17-Apr-12 2:06am
Edited 17-Apr-12 2:14am
Mehdi Gholam282.7K
ryanb31 at 17-Apr-12 8:11am
Just put breakpoints and see what image6.Source is. This doesn't seem like it should be hard.
xbolslock at 17-Apr-12 8:17am
ya i know. i tried. but it gives me {System.Windows.Media.Imaging.BitmapImage}. thats the troubling part.
ryanb31 at 17-Apr-12 8:24am
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

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:

if (0 == String.Compare(
Marcus Kramer at 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 at 11-Dec-12 12:12pm
True, however if someone else is having the problem his solution just might help.
Marcus Kramer at 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 at 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 at 5-May-14 6:54am
Thanks @jesse :) :) .. it was really helpful :)
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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.
xbolslock at 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)

  Print Answers RSS
0 stibee 313
1 295
2 OriginalGriff 295
3 himanshu agarwal 184
4 Sergey Alexandrovich Kryukov 154
0 OriginalGriff 9,031
1 Sergey Alexandrovich Kryukov 8,513
2 Mika Wendelius 6,922
3 F-ES Sitecore 2,388
4 Suvendu Shekhar Giri 2,320

Advertise | Privacy | Mobile
Web01 | 2.8.150728.1 | Last Updated 11 Dec 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100