C++/CLI with XAML
MSDNから写すばかりじゃなんなので、試してみました。
Appendant.cpp
#include "AppendantApp.h" using namespace Appendant; [STAThreadAttribute] int main(array<System::String ^> ^args) { AppendantApp app; app.Run(); return 0; }
AppendantApp.h
using namespace System; using namespace System::IO; using namespace System::Windows; using namespace System::Windows::Markup; using namespace System::Windows::Navigation; namespace Appendant { public ref class AppendantApp : public System::Windows::Application { public: AppendantApp(void) {} virtual ~AppendantApp(void) {} virtual void OnStartup(StartupEventArgs^ e) override { FileStream^ fstream = gcnew FileStream("AppendNaviWin.xaml", FileMode::Open, FileAccess::Read); NavigationWindow^ win = safe_cast<NavigationWindow^>( XamlReader::Load(fstream) ); if ( win != nullptr ) win->Show(); } }; }
AppendantNaviWin.xaml
<?xml version="1.0" encoding="utf-8"?> <NavigationWindow xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:u="clr-namespace:Appendant.AppendNaviWin;assembly=Appendant" Name="AppendNaviWin" Title="Appendant Navigation Window" />
これをコンパイルして実行すると、見事、Title に「Appendant Navigation Window」が表示されます。
後は、コード・ビハインドをどうやって実現するかってところですね。