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^)
System::Windows::Serialization::Parser::LoadXml(stream);
stream->Close();
... 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:
<Page
xmlns="https://schemas.microsoft.com/winfx/avalon/2005"
xmlns:x="https://schemas.microsoft.com/winfx/xaml/2005"
>
....
<ContextMenu>
<MenuItem x:Name="newShipment" Header="New Shipment"/>
</ContextMenu>
Note -- it's important that the root xaml tag support INameScope (which Page and Window do), otherwise FindName won't work.