C# 导航服务抱怨;FileNotFound";从未附加到任何视图的类执行

C# 导航服务抱怨;FileNotFound";从未附加到任何视图的类执行,c#,silverlight,windows-phone-7,navigateuri,C#,Silverlight,Windows Phone 7,Navigateuri,我试图从某个类导航到另一个页面(使用UriMapping),该类处理服务器API,但它不起作用。这是我的代码: public void processResponce(item Response) { try { var token = Response.result.token; this.setToken("&token=" + token); Debug.WriteLine(this.apiUrl);

我试图从某个类导航到另一个页面(使用UriMapping),该类处理服务器API,但它不起作用。这是我的代码:

public void processResponce(item Response)
{
    try
    {
        var token = Response.result.token;
        this.setToken("&token=" + token);
        Debug.WriteLine(this.apiUrl);

        (Application.Current.RootVisual as PhoneApplicationFrame).Navigate(new Uri("/listItems", UriKind.Relative));
    }
    catch
    {
        Deployment.Current.Dispatcher.BeginInvoke(() =>
            {
                var messageFromServer = Response.error.message;
                MessageBox.Show(messageFromServer);

                Debug.WriteLine(messageFromServer);
            });
    }
}
SDK一直说,该文件不存在。但如果我从某个类调用Navigate(),并附加到视图(fe,MainPage.xaml.cs),那么导航就会成功。 有人能帮忙吗

UPD.我有多个*.xaml页面,但该类没有直接连接到另一个页面。现在,这个类名为“JSON-RPC”。我尝试了不同的方法来解决我的问题(甚至将他命名为“public partial JSON-RPC:PhoneApplicationPage”),但是。。。问题是:若我将从某个类调用Navigate(),该类附加到*.xaml页面(在解决方案资源管理器中,它显示为一个树-*.xaml页面->pagename.xaml.cs),那个么它可以工作;如果我从类JSON-RPC调用Navigate(),那么它总是说“找不到文件”

UPD2。解决方案: 有时我觉得自己是个傻瓜。 答案是:

  Deployment.Current.Dispatcher.BeginInvoke(() =>
             {
                  (Application.Current.RootVisual as PhoneApplicationFrame).Navigate(new Uri("/listItems", UriKind.Relative));
             });
  Deployment.Current.Dispatcher.BeginInvoke(() =>
             {
                  (Application.Current.RootVisual as PhoneApplicationFrame).Navigate(new Uri("/listItems", UriKind.Relative));
             });
我们需要调用Dispatcher来解决此问题。

请确保:

  • 在uri的末尾包含“.xaml”扩展名
  • 您可以完全指定文件的路由(对于/listItems),请确保 listItems.xaml位于应用程序的根目录下)
  • 构建操作 将xaml文件的页设置为“Page”
另外:您可以使用RootFrame而不是RootVisual

下面是一个适合我的例子:

App.Current.RootFrame.Navigate(new Uri("/Pages/Error.xaml?Message=Application error", UriKind.Relative));
确保:

  • 在uri的末尾包含“.xaml”扩展名
  • 您可以完全指定文件的路由(对于/listItems),请确保 listItems.xaml位于应用程序的根目录下)
  • 构建操作 将xaml文件的页设置为“Page”
另外:您可以使用RootFrame而不是RootVisual

下面是一个适合我的例子:

App.Current.RootFrame.Navigate(new Uri("/Pages/Error.xaml?Message=Application error", UriKind.Relative));

有时我觉得自己是个傻瓜。 答案是:

  Deployment.Current.Dispatcher.BeginInvoke(() =>
             {
                  (Application.Current.RootVisual as PhoneApplicationFrame).Navigate(new Uri("/listItems", UriKind.Relative));
             });
  Deployment.Current.Dispatcher.BeginInvoke(() =>
             {
                  (Application.Current.RootVisual as PhoneApplicationFrame).Navigate(new Uri("/listItems", UriKind.Relative));
             });

我们需要调用Dispatcher来解决这个问题。

有时我觉得自己是个傻瓜。 答案是:

  Deployment.Current.Dispatcher.BeginInvoke(() =>
             {
                  (Application.Current.RootVisual as PhoneApplicationFrame).Navigate(new Uri("/listItems", UriKind.Relative));
             });
  Deployment.Current.Dispatcher.BeginInvoke(() =>
             {
                  (Application.Current.RootVisual as PhoneApplicationFrame).Navigate(new Uri("/listItems", UriKind.Relative));
             });

我们需要调用Dispatcher来解决此问题。

我不确定是否理解您的意思,您的名称末尾是否缺少“.xaml”?否。我有多个*.xaml页面,但该类未直接连接到另一个页面。现在,这个类名为“JSON-RPC”。我尝试了不同的方法来解决我的问题(甚至将他命名为“public partial JSON-RPC:PhoneApplicationPage”),但是。。。问题是:若我将从某个类调用Navigate(),该类附加到*.xaml页面(在解决方案资源管理器中,它显示为一个树-*.xaml页面->pagename.xaml.cs),那个么它可以工作;如果我从我的类JSON-RPC调用Navigate(),那么它总是说“找不到文件”。我不确定我是否理解您的意思,您是否在名称末尾缺少一个“.xaml”?不。我有多个*.xaml页面,但这个类没有直接连接到另一个页面。现在,这个类名为“JSON-RPC”。我尝试了不同的方法来解决我的问题(甚至将他命名为“public partial JSON-RPC:PhoneApplicationPage”),但是。。。问题是:若我将从某个类调用Navigate(),该类附加到*.xaml页面(在解决方案资源管理器中,它显示为一个树-*.xaml页面->pagename.xaml.cs),那个么它可以工作;如果我从我的类JSON-RPC调用Navigate(),那么它总是说“找不到文件”。1。我正在使用UriMapping,在App.xaml中声明了UriMaps:


3。建立行动?不太确定我是否理解了这一点。
另外,root frame在System.Windows.Application中不存在:(另外,如果我要对页面使用完整Uri(“/Views/ListItemsAndSomethingElse.xaml”)+UriKind.Relative/Absolute…它不起作用。请检查xaml文件的属性。您应该会看到一个名为Build action的属性,它告诉VS如何构建文件。此外,我会尝试注释UriMapper,看看它是否导致了问题。除此之外,我没有进一步的想法:)如果您想打开标记,那么在解决方案资源管理器中选择xaml文件,然后点击F4,您应该会看到该文件的属性。此外,您的类是否与您尝试导航到的页面位于同一程序集中?1。我正在使用UriMapping,在App.xaml中声明了UriMaps:


3。建立行动?不太确定我是否理解了这一点。
另外,root frame在System.Windows.Application中不存在:(另外,如果我要对页面使用完整Uri(“/Views/ListItemsAndSomethingElse.xaml”)+UriKind.Relative/Absolute…它不起作用。请检查xaml文件的属性。您应该会看到一个名为Build action的属性,它告诉VS如何构建文件。此外,我会尝试注释UriMapper,看看它是否导致了问题。除此之外,我没有进一步的想法:)如果您想打开标记,那么在解决方案资源管理器中选择xaml文件,然后点击F4,您应该会看到该文件的属性。另外,您的类是否与您尝试导航到的页面位于同一程序集中?