System.TypeLoadException无法找到Windows运行时类型“Windows.Foundation”异常 [英] System.TypeLoadException Could not find Windows Runtime type 'Windows.Foundation' exception
问题描述
在我的Windows Phone 8.1应用程序中,我正在创建一个CustomPage,然后导航到它,所有代码都在后面。我的CustomPage类是:
使用Windows.UI.Xaml.Controls;
命名空间TestApp {
公共类CustomPage:Page {
public CustomPage(){
this.BuildPage();
}
private void BuildPage(){
var panel = new StackPanel();
panel.Children.Add(new TextBlock {Text =Hello World});
this.Content = panel;
}
}
}
然后在我的MainPage.xaml.cs中我这样做:
CustomPage myNewPage = new CustomPage();
Frame.Navigate(myNewPage.GetType());
但是这会引发System.TypeLoadException异常 - 找不到Windows运行时类型'Windows.Foundation'
如果我不做一个CustomPage类只是一个Page类,它工作正常,但我需要创建一个CustomPage类,我怎么能解决这个问题?
您可以使用typeOf运算符来获取您的客户页面的类型,如下所示。
typeof运算跨度>(myNewPage);
In my Windows Phone 8.1 app I'm creating a CustomPage and then navigating to it, all in code behind. My CustomPage class is:
using Windows.UI.Xaml.Controls; namespace TestApp { public class CustomPage : Page { public CustomPage() { this.BuildPage(); } private void BuildPage() { var panel = new StackPanel(); panel.Children.Add(new TextBlock { Text = "Hello World" }); this.Content = panel; } } }
And then in my MainPage.xaml.cs I'm doing this:
CustomPage myNewPage = new CustomPage(); Frame.Navigate(myNewPage.GetType());
However this throws a System.TypeLoadException exception - Could not find Windows Runtime type 'Windows.Foundation'
If I don't do a CustomPage class just a Page class, it works fine, but I need to create a CustomPage class, how could I solve this?
You can use typeOf operator for getting the type of your custome page like below.
typeof(myNewPage);
这篇关于System.TypeLoadException无法找到Windows运行时类型“Windows.Foundation”异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!