无法解析Uri.path,相对路径和绝对路径之间的冲突

时间:2013-11-29 05:57:30

标签: c# xaml keyvaluepair

我有以下代码,我无法正常工作:

 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;
      }

我有一个名为'item'的对象的键/值对,如果键值为“?”,我想使异常触发不同的代码块。找到了。上面我使用switch语句尝试执行另一个代码块,如果“?”被发现是一个键,否则执行默认代码块。但是现在我在运行上面的代码时触发了以下豁免:

// 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();
    }
}

我想知道是否有人能给我一个线索,说明为什么会这样。感谢任何帮助。谢谢。

2013年12月27日增加:

下面的代码块来自一个包含很长网站列表的文件,但最后一行不是网站,而是我想要调用的程序中的文件。

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))
    };
  }
}

最后一行new Element("? About", new Uri("/Shared/About/AboutPage.xaml?appName=Elements", UriKind.Relative))是保存程序中文件链接的行。这里使用switch语句的第一个代码块应该确定这行代码中的?,但我不确定我做得对。第二个代码块是测试程序时调试器抛出的代码。

0 个答案:

没有答案
相关问题