programming

minimum xaml in c++/cli

Below is what I think is a minimum xaml app using c++/cli. I am obviously blind because I could not find ANY actual samples or examples on the intarweb. Apparently there are only 5 people on the planet using c++/cli. Of course I could just give in and join the c# bandwagon, but I like to do things the difficult way. The xaml itself is embedded in the code as an escaped string (it is stole from C# sample quickstart3 btw).

Not having any documentation was annoying, but since the API is actually designed reasonably unlike most of their past APIs, it was pretty trivial to guess what the hell they wanted. If anyone finds the magic documentation location about any c++/cli action, please tell me about it. Google is not behaving.

Speaking of Google not behaving.. These forums are not being crawled by Google. I looked around for a robots.txt that would kill it, but didn't find anything. Anyone know what is up with that? I guess more people that I personally know visit the site than I thought. REGISTER BITCHES! haha.

Anyway.. Next up is to bind those buttons and get it working with DirectX. If I was using C# then a bunch of IDE voodoo happens behind the scenes and can generate a bunch of CRAP for you. I am anti-IDE voodoo, so that is fine with me.

btw. This technically is my first c++/cli app, I have no idea what the hell I am doing and it has 0 error checking, so keep that in mind.

I put a zip up here: http://z425.com/files/minimum_xaml.zip

The references needed are:

PresentationCore
PresentationFramework
System.Xml
Windows.Base

Code:

using namespace System;
using namespace System::IO;
using namespace System::Windows;
using namespace System::Windows::Serialization;

public ref class LameWindow : public Window
{
};

public ref class LameApplication : public Application
{
};


[STAThreadAttribute]
int main(array<System::String ^> ^args)
{
   MemoryStream^ ms = gcnew MemoryStream();
   StreamWriter^ sw = gcnew StreamWriter(ms);
   String^ str =
      "<DockPanel xmlns=\"http://schemas.microsoft.com/winfx/avalon/2005\"> \
         <TextBlock Background=\"LightBlue\" DockPanel.Dock=\"Top\">Some Text </TextBlock> \
         <TextBlock DockPanel.Dock=\"Bottom\" Background=\"LightYellow\">Some text at the bottom of the page.</TextBlock> \
         <TextBlock DockPanel.Dock=\"Left\" Background=\"Lavender\">Some More Text</TextBlock> \
         <DockPanel Background=\"Bisque\"> \
            <StackPanel DockPanel.Dock=\"Top\"> \
               <Button HorizontalAlignment=\"Left\" Height=\"30px\" Width=\"100px\" Margin=\"10,10,10,10\">Button1</Button> \
               <Button HorizontalAlignment=\"Left\" Height=\"30px\" Width=\"100px\" Margin=\"10,10,10,10\">Button2</Button> \
            </StackPanel> \
            <TextBlock  Background=\"LightGreen\">Some Text Below the Buttons</TextBlock> \
         </DockPanel> \
      </DockPanel>";   
      
   sw->Write(str);
   sw->Flush();
   ms->Flush();
   ms->Position = 0;
   
   Window^ window=gcnew LameWindow();
   window->Content=(UIElement^)XamlReader::Load(ms);
   
   Application^ app=gcnew LameApplication();
   app->MainWindow=window;
   app->MainWindow->Show();
   app->Run();

   return 0;
}