C++ and uncompiled xaml

You can't use C++ with compiled xaml in the same assembly.  My preferred solution is to create a second assembly (C# and xaml), but another solution is to use uncompiled xaml (Parser.LoadXml).  Here's what it would look like if my MFC demo used LoadXml:

System::IO::Stream^ stream = System::IO::File::OpenRead("c:\\coding\\CppLoadXml\\AvalonControlLibrary1\\Page1.xaml");
System::Windows::Controls::Page^ page = (System::Windows::Controls::Page^)
... do whatever initialization, including hookup some event handlers: ...
System::Windows::Controls::MenuItem^ item = (System::Windows::Controls::MenuItem^) page->FindName("newShipment");
item->Click += gcnew RoutedEventHandler(data, &ManagedDocument::NewShipment);

Where the xaml was:

               <MenuItem x:Name="newShipment" Header="New Shipment"/>

Note -- it's important that the root xaml tag support INameScope (which Page and Window do), otherwise FindName won't work.

Comments (0)

Skip to main content