2014-03-06 2 views
-3

I Windows Phone 8 응용 프로그램에서 작업 중입니다.이미지 리소스가 null인지 확인하십시오.

string Image = "/MyData/" + myObject.ImageName + "big.png"; 
BitmapImage bmp = new BitmapImage(new Uri(Image , UriKind.Relative)); 

       MyImage.Source = bmp; 

내가 폴더에 이미지가의 MyData /, 내가 <imagename>big.png,<imagename>small.png.

그래서 여기에 무슨 일이 일어나고 있는지

내가 <imagename>big.png이 위치에 존재하거나하지 않을 경우, 그렇지 않은 경우 확인하려면처럼 이미지의 2 개 세트가 선택 <imagename>small.png.

어떻게 수행하나요?

편집 내가 여기 어떻게 나 자신을 해결했다.

File.Exists("path to file") here path should be `folderName/filenames` and not `/folderName/filenames` 

나를 도와 주신 모든 분들께 감사드립니다.

+0

왜 downvote? 이 질문에 뭐가 잘못 되었나요? – user3114009

+0

File.Exists 메소드를 사용해 보셨습니까? –

+0

@ JagathMurali 네, 시도해 보았습니다. 작동하지 않습니다. – user3114009

답변

0
string image = "/MyData/" + myObject.ImageName + "/big.png"; 
string fileName = Path.GetFileName(image); 
if(!string.IsNullOrEmpty(fileName)) 
{ 
MessageBox.Show("File Exist -"+fileName); 
} 
else 
{ 
MessageBox.Show("No File Exist -"); 
} 
BitmapImage bmp = new BitmapImage(new Uri(image , UriKind.Relative)); 
if(bmp==null) 
{ 
image = "/MyData/" + myObject.ImageName + "/small.png"; 
bmp = new BitmapImage(new Uri(image , UriKind.Relative)); 
} 
MyImage.Source = bmp; 
+0

잘 작동하지 못했습니다. – user3114009

+0

내 ans에서 수정했습니다. 보기 – Jaihind

+0

변경 사항은 무엇입니까? – user3114009

관련 문제