I have the following code I can't get to work right:
KeyValuePair<string, object> item =
(KeyValuePair<string, object>)e.AddedItems[0];
string str = (string)item.Key;
switch (str)
{
case "?":
this.NavigationService.Navigate(new Uri("/Shared/About/AboutPage.xaml?appName=Elements",
UriKind.Relative));
break;
default:
this.NavigationService.Navigate(new Uri("/DetailsPage.xaml?url=" +
HttpUtility.UrlEncode((item.Value as Element).Url.LocalPath),
UriKind.Relative));
break;
}
I have key/value pairs for an object named 'item' and I would like to make the exception to trigger a different code block if the key value "?" is found. Above I used a switch statement to try to execute another code block if "?" is found as a key, otherwise a default code block is executed. But right now I am getting the following exemption triggered when I run the above code:
// Code to execute on Unhandled Exceptions
private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
{
if (System.Diagnostics.Debugger.IsAttached)
{
// An unhandled exception has occurred; break into the debugger
System.Diagnostics.Debugger.Break();
}
}
I am wondering if anyone can give me a clue as to why this is happening. Any help is appreciated, thanks.
ADDED 12/27/2013:
The code block below is from a file that holds a long list of websites, but the last line is not a website but a file within the program I want called instead.
using System;
namespace ...
{
public class Data
{
public static readonly Element[] Elements = {
new Element("Hydrogen [H] 1", new Uri("http://chemistry.about.com/od/elementfacts/a/hydrogen.htm")),
new Element("Helium [He] 2", new Uri("http://chemistry.about.com/od/elementfacts/a/helium.htm")),
...
new Element("? About", new Uri("/Shared/About/AboutPage.xaml?appName=Elements", UriKind.Relative))
};
}
}
The last line new Element("? About", new Uri("/Shared/About/AboutPage.xaml?appName=Elements", UriKind.Relative))
is the line that holds the link to the file within the program. The first block of code here with the switch statement is supposed to determine the ?
in this line of code but I'm not sure I'm doing it right. The second block of code is what is thrown by the debugger when I test the program.