c# - 对象引用未设置为 Windows 8 应用程序中对象的实例

标签 c# .net windows-8

因此,在查阅了无数资源以试图找出这真正意味着什么之后,我发现没有任何用处。让我们把它弄清楚,我知道错误是什么意思。但我不知道是什么原因造成的。我的代码如下:

private void Button_Click_1(object sender, RoutedEventArgs e)
{
    ListView selector = this.itemListView;
    FeedItem item = selector.SelectedItem as FeedItem;
    if (item != null && this.Frame != null)
    {
        this.Frame.Navigate(typeof(WebViewPage), item.Title); //This line is the problem
    }
}   

我试图做的是根据 itemListView 中的选择导航到完整的 webview 页面。我通过使用 AppBar 按钮来完成此操作。当我逐行执行此代码时,一切都按预期运行,直到我尝试导航。在导航之前,我的所有对象都不为空(根据智能感知和输入 if 语句的事实),并且在我单步执行导航后它仍然保持这种状态。该程序不会失败,它只是在 Intellitrace 框中显示为异常,并且导航从未发生,让用户随心所欲地单击应用栏按钮,但无济于事。

Webview 页面代码(根据 IntelliTrace,我实际上从未访问过此页面中的任何代码)。

protected override void LoadState(Object navigationParameter, Dictionary<String,Object> pageState)
{
    FeedItem item = FeedUtilities.GetItemByTitle((string)navigationParameter);
    pageTitle.DataContext = item;

    itemContentWebView.Navigate(item.Link);
}

这几天一直让我很沮丧,所以非常感谢任何帮助。

最佳答案

试试这个:

var rootFrame = new Frame();
rootFrame.Navigate(typeof(SearchResultsPage1));

Window.Current.Content = rootFrame;
Window.Current.Activate(); 

关于c# - 对象引用未设置为 Windows 8 应用程序中对象的实例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13307460/

相关文章:

c# - C++和C#之间HRESULT的转换

C# Response.Write pdf 不适用于 Android 浏览器

javascript - 服务器和浏览器日期差异

c#:命名空间优先级/优先级?有2个同名类(class)

c# - 将复选框状态保存到本地设置,windows 8

windows-8 - 适用于Windows 8的可再发行的离线.NET Framework 3.5安装程序

c# - TransactionScope 提交更新而不调用 .Complete() 但不插入

c# - 如何以编程方式为 WCF 服务创建自签名证书?

c# - 在 C# 中将\u0040 转换为 @

javascript - WinJS Promise 然后出错