Creating pages in the Windows Store without XAML

I am writing a C # / XAML application for the Windows Store and would like to create and navigate to the page and fully display the page from C #. Is it possible? Obviously, I can inherit from the page, but when I try to go to a derived page that does not have XAML, I get a System.TypeLoadException ... "Could not find a Windows Runtime of type" Windows.Foundation ".

My thought was that this should be possible, since XAML is converted to a definition of a partial CLR class, so there is no reason that there was nothing in C #. But obviously, I missed some kind of structure requirement.

Suggestions?

Currently, all that I have for the derived page,

using Windows.UI.Xaml.Controls; namespace App1 { public class Page2 : Page { public Page2 () { } } } 

And here is the complete 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() 
+7
c # windows-store-apps windows-runtime xaml
source share
2 answers

I can give an example for a simple page

 using System; using Windows.ApplicationModel.Activation; using Windows.UI; using Windows.UI.Xaml; using Windows.UI.Xaml.Controls; using Windows.UI.Xaml.Media; namespace MyApp { class Program { public static void Main (string[] args) { Application.Start((p) => new MyApp()); } } class MyApp : Windows.UI.Xaml.Application { public MyApp(){} protected override void OnLaunched(LaunchActivatedEventArgs args) { var layoutRoot = new Grid() { Background = new SolidColorBrush(Colors.Blue) }; layoutRoot.Children.Add(new Button() { Content = "Hello!" }); Window.Current.Content = layoutRoot; Window.Current.Activate(); } } } 

Replace these paths with the correct elements when compiling:

 C:\Windows\Microsoft.NET\Framework\v4.0.30319\csc.exe /target:appcontainerexe /r:"C:\Windows\Microsoft.NET\Framework\v4.0.30319\System.Runtime.WindowsRuntime.dll" /r:"C:\Windows\Microsoft.NET\Framework\v4.0.30319\System.Runtime.dll" /r:"C:\Windows\System32\WinMetadata\windows.applicationmodel.winmd" /r:"C:\Windows\System32\WinMetadata\windows.ui.winmd" /r:"C:\Windows\System32\WinMetadata\windows.ui.xaml.winmd" /r:"C:\Windows\System32\WinMetadata\windows.media.winmd" MyApp.cs 
0
source share

You can create dynamic XAML using LINQ and XML.

Here is an example of how to create a dynamic TextBlock ; you can use this concept to apply it to the Page element:

http://msdn.microsoft.com/en-us/library/cc189044(v=vs.95).aspx

-one
source share

All Articles