Frage

I am trying to transfer data on between pages. And I am writting below code. PivotPage.xaml.cs code;

if (Convert.ToDouble(PhoneApplicationService.Current.State["futbol"]) != null)
   futbol = Convert.ToDouble(PhoneApplicationService.Current.State["futbol"]);
else
   futbol = 0.0;

User can select or not select "futbol". If selected "futbol" not problem. But If not selected "futbol" give an error.

Error: An exception of type 'System.Collections.Generic.KeyNotFoundException' occurred in mscorlib.ni.dll but was not handled in user code

Additional information: The given key was not present in the dictionary.

How can I using "Current.State" or another function?

Thanks in advance. (sorry my language)

War es hilfreich?

Lösung

You need to check if the "futbol" is present in the State collection.

futbol = PhoneApplicationService.Current.State.ContainsKey("futbol")
    ? Convert.ToDouble(PhoneApplicationService.Current.State["futbol"])
    : 0.0;

Also, feel free to read this article on different ways of storing data on Windows Phone 8

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top