Click here to Skip to main content
12,398,181 members (57,811 online)
Rate this:
 
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??

Thanks!
Posted 17-Apr-12 2:06am
Updated 17-Apr-12 2:14am
Mehdi Gholam314.3K
v2
Comments
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
   
http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.bitmapimage.aspx
Rate this: bad
 
good
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(
        imageSource1.ToString(),
        imageSource2.ToString(),
        StringComparison.OrdinalIgnoreCase))
{
    ...
}
  Permalink  
v2
Comments
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
 
good
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.
  Permalink  
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)

  Print Answers RSS
Top Experts
Last 24hrsThis month


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