I am writing a C#/XAML Windows Store app and would like to create and navigate to and display a Page entirely from C#. Is this possible? Obviously I can inherit from Page, but, when attempting to Navigate to a derived Page that has no XAML, I get a System.TypeLoadException... "Could not find Windows Runtime type 'Windows.Foundation'".
My thought was this should be possible since XAML translates into a CLR partial class definition, so there's no reason one couldn't do everything in C#. But obviously I missing some sort of framework requirement.
Suggestions?
Right now all I have for the derived Page is
using Windows.UI.Xaml.Controls;
namespace App1 {
public class Page2 : Page {
public Page2 () { }
}
}
And here is the full exception:
Could not find Windows Runtime type 'Windows.Foundation'.
at System.StubHelpers.WinRTTypeNameConverter.GetTypeFromWinRTTypeName(String typeName, Boolean& isPrimitive)
at System.StubHelpers.SystemTypeMarshaler.ConvertToManaged(TypeNameNative* pNativeType, Type& managedType)
at Windows.UI.Xaml.Controls.Frame.Navigate(Type sourcePageType)
at App1.MainPage.<P2>d__2.MoveNext()
I can give an example for a simple page
Replace these paths with the correct items when compiling:
You can create dynamic XAML using LINQ and XML.
Here's an example on how to create a dynamic TextBlock; you can use the concept to apply it to a Page element:
http://msdn.microsoft.com/en-us/library/cc189044(v=vs.95).aspx