Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 89864

Help please: SetBinding(ImageCell.ImageSourceProperty, “IconSource”) (String) crash on WP

$
0
0

Hi all
In my app I use master-detail-navigation menu with a few ImageCells in a list.
Further, I have a search-page, with a ListView containing also ImageCells.
The imagename is stored as string in a list that is bound to the ImageCell.
The Images are stored in the project (in WP-Project in the root).
If I run the app in iOS and Android, it run’s without problem.
If I run it in WP, the loading of the pages with the ImageCell’s is extremely slow and in VS2013 errors for each ImageCell are displayed (translated to English):
An exeption (first chance) of type "System.InvalidCastException" is occurred in in mscorlib.ni.dll
The app the don’t crash but take a very long time - after that, the images are shown anyway.

I have searched for days until I was able to find out what causes the problem (as I was not able to find the code-line by debugging (not in my own code).
I then found a great tip In stackoverflow (to show also such exeptions in more detail):
Pressing CTRL-Alt-E in debug-mode shows up a form, where exceptions can be configured - don’t know that before - may be interesting for every developer that also don't know that).

Thanks this tip, I was able to find out the problem - here it comes (minimum-information):
I have an object for the menu-options, where I fill in the names of the images as string (code to one option):

OptionItems.Add(new MenuOption { Titel = "FreizeitGuide", Details = "Hier finden Sie viele interessante Freizeitmöglichkeiten...", IconSource = "FreizeitGuide.png" }); 

I then set the bindings to the image of the ImageCell:

cell.SetBinding(ImageCell.ImageSourceProperty, "IconSource");

The real (underlaying) exception at runtime (only in WP, not in iOS and Android) is (to every ImageCell):
Invalid cast from 'System.String' to 'Xamarin.Forms.ImageSource'

So.. my conclusion is:
In the binding (at runtime), XF converts “automatically” the string containing the Image-Name to Xamarin.Forms.ImageSource for iOS and Android, but not for WP.

So my question is, how to solve that problem?
Is there a chance to change the Setbinding:

cell.SetBinding(ImageCell.ImageSourceProperty, "IconSource");

to something, that casts automatically the string into Xamarim.Forms.ImageSource?

Thanks a lot for any suggestions - I see the bug but don't know how to solve it.

@MihaMarkic‌:
If have seen, that you have posted some similar information's in stackoverflow.
Maybe you can give me a tip...?


Viewing all articles
Browse latest Browse all 89864

Trending Articles