在我的Windows Phone 8.1应用程序中,我创建了一个CustomPage,然后导航到它,所有代码都在后面。我的CustomPage类是:
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;
}
}
}
然后在我的MainPage.xaml.cs
我这样做:
CustomPage myNewPage = new CustomPage();
Frame.Navigate(myNewPage.GetType());
但是这会引发System.TypeLoadException异常 - Could not find Windows Runtime type 'Windows.Foundation'
如果我不做一个CustomPage类只是一个Page类,它工作正常,但我需要创建一个CustomPage类,我怎么能解决这个问题?
更新的
这是堆栈跟踪
MyCustomClass.DLL!HelpingTool.NavigateToNewPage() Line 50 C#
MyCustomClass.DLL!HelpingTool.InitializeToolset() Line 23 C#
MyCustomClass.DLL!HelpingTool.HelpingTool(Windows.UI.Xaml.Controls.Page mainPage = {TestApp.MainPage}) Line 18 C#
TestApp.exe!TestApp.MainPage.Button_Click(object sender = {Windows.UI.Xaml.Controls.Button}, Windows.UI.Xaml.RoutedEventArgs e = {Windows.UI.Xaml.RoutedEventArgs}) Line 88 C#
和我的MainPage.xaml的内容
<Page
x:Class="TestApp.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:TestApp"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Loaded="Page_Loaded"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid x:Name="LayoutRoot">
<Grid.RowDefinitions>
<RowDefinition Height="2*" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid x:Name="myGrid" Grid.Row="0">
<TextBlock x:Name="OutputText">
Output will appear here <LineBreak />
</TextBlock>
</Grid>
<ScrollViewer Grid.Row="1" VerticalAlignment="Stretch">
<Button Content="Do something" Click="Button_Click" HorizontalAlignment="Center" />
</ScrollViewer>
</Grid>
</Page>