Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/320.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 无法解析Uri.path,相对路径和绝对路径之间存在冲突_C#_Xaml_Keyvaluepair - Fatal编程技术网

C# 无法解析Uri.path,相对路径和绝对路径之间存在冲突

C# 无法解析Uri.path,相对路径和绝对路径之间存在冲突,c#,xaml,keyvaluepair,C#,Xaml,Keyvaluepair,我有以下代码,无法正常工作: KeyValuePair<string, object> item = (KeyValuePair<string, object>)e.AddedItems[0]; string str = (string)item.Key; switch (str) { case "?": this.NavigationService.Navigate

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

 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;
      }
我想知道是否有人能告诉我为什么会发生这种情况。谢谢你的帮助

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

最后一行
newelement(“?About”,newURI(/Shared/About/AboutPage.xaml?appName=Elements”,UriKind.Relative))
是保存程序内文件链接的行。这里带有switch语句的第一块代码应该确定这行代码中的
,但我不确定我做得是否正确。第二个代码块是调试程序在测试程序时抛出的代码。

抛出的异常是什么?从您的代码示例中,我无法确定一个明显的原因,即如果“”是键,为什么没有达到“”的代码。请添加有关问题和引发的异常的更多详细信息。当我使用上面的第一个代码块运行代码时,第二个代码块将显示“code”System.Diagnostics.Debugger.Break();”“代码”代码行高亮显示。因此,它正在闯入“code”私有无效应用程序\u UnhandledException(对象发送方,ApplicationUnhandledExceptionEventArgs e){…}“code”函数。当我单击正在调试的应用程序上的选项卡时,会发生这种情况,“?”表示其中一个选项卡。它应该带我去…/AboutPage.xaml文件。其他选项卡将我带到由switch语句中的默认值表示的外部web链接。我不确定还能添加什么。我在上面添加了更多的细节,包括链接到这部分代码的代码文件。谢谢
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))
    };
  }
}