【问题标题】:An exception of type 'System.ArgumentException' occurred in Microsoft.Phone.ni.dll but was not handled in user codeMicrosoft.Phone.ni.dll 中出现“System.ArgumentException”类型的异常,但未在用户代码中处理
【发布时间】:2014-02-27 07:09:22
【问题描述】:

我正在尝试在 windows phone8 移动应用程序中从 1 个页面导航到其他页面。 它给出错误- System.Windows.ni.dll 中出现“System.Reflection.TargetInvocationException”类型的未处理异常

附加信息:调用目标已引发异常。

XAML:

<phone:PivotItem Header="item1">
    <Grid>
        <StackPanel>
            <HyperlinkButton Content="Transfer" Click="hyperlinkButton1_Click" />
        </StackPanel>
    </Grid>
</phone:PivotItem>

C#代码:

private void hyperlinkButton1_Click(object sender, RoutedEventArgs e)
{
    //NavigationService.Navigate(new Uri("/AboutUs.xaml", UriKind.Relative));               

    //NavigationService.Navigate(new Uri("/AboutUs.xaml", UriKind.Relative));
    Dispatcher.BeginInvoke(() =>
    {
        this.NavigationService.Navigate(new Uri("/AboutUs.xaml", UriKind.Relative));
    });
}

【问题讨论】:

  • 您将不需要调度程序,因为您已经在 UI 线程上运行了。但是您确定页面名称及其位置吗?调试时,在导航服务上调用 Navigate 后抛出异常?

标签: wpf xaml windows-phone-8 app.xaml


【解决方案1】:

我认为你需要两个步骤:

  1. 移除 Dispatcher 的块,你在 Click 方法中的 UI 线程上。只是:

    NavigationService.Navigate(new Uri("your uri", UriKind.Relative));

  2. 勾选你要导航的uri字符串,如SpellUp or Low Case等。

【讨论】:

  • NavigationService.Navigate(new Uri("/Views/AboutUs.xaml", UriKind.Relative));现在它为我工作
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-03-31
  • 2016-02-13
  • 2018-10-25
相关资源
最近更新 更多