Click here to Skip to main content
12,951,289 members (58,339 online)
Rate this:
Please Sign up or sign in to vote.
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:
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
Updated 17-Apr-12 2:14am
ryanb31 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.
ryanb31 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 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.
Marcus Kramer 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 :)
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 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
Top Experts
Last 24hrsThis month
OriginalGriff 6,084
CHill60 3,480
Maciej Los 3,083
Jochen Arndt 1,975
ppolymorphe 1,830

Advertise | Privacy | Mobile
Web02 | 2.8.170525.1 | Last Updated 11 Dec 2012
Copyright © CodeProject, 1999-2017
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