Click here to Skip to main content
Rate this: bad
good
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 3:06am
Edited 17-Apr-12 3:14am
Mehdi Gholam253.5K
v2
Comments
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
   
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 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
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 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 George Jonsson 175
1 Kornfeld Eliyahu Peter 169
2 Zoltán Zörgő 139
3 PIEBALDconsult 130
4 OriginalGriff 120
0 OriginalGriff 6,165
1 DamithSL 4,658
2 Maciej Los 4,107
3 Kornfeld Eliyahu Peter 3,649
4 Sergey Alexandrovich Kryukov 3,342


Advertise | Privacy | Mobile
Web03 | 2.8.141220.1 | Last Updated 11 Dec 2012
Copyright © CodeProject, 1999-2014
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