Skip to content

Commit

Permalink
Window loads and has nav bar :o
Browse files Browse the repository at this point in the history
Now to add some content
  • Loading branch information
fredemmott committed Feb 13, 2022
1 parent f00b0ab commit 8a8539a
Showing 1 changed file with 41 additions and 9 deletions.
50 changes: 41 additions & 9 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
#include <winrt/base.h>
#include <winrt/Microsoft.UI.Xaml.h>
#include <winrt/Microsoft.UI.Xaml.Controls.h>
#include <winrt/Windows.Foundation.Collections.h>
#include <winrt/Microsoft.UI.Xaml.Markup.h>
#include <winrt/Microsoft.UI.Xaml.XamlTypeInfo.h>
#include <winrt/Microsoft.Windows.ApplicationModel.DynamicDependency.h>
#include <winrt/Windows.UI.Xaml.Hosting.h>
#include <winrt/Windows.Foundation.Collections.h>

// Undocumented static initializer for MddBootstrap; using it instead of documented
// APIs for now,
// APIs for now, to be closer to what Visual Studio does
#include <MddBootstrapAutoInitializer.cpp>

namespace muxc = winrt::Microsoft::UI::Xaml::Controls;
Expand All @@ -22,26 +23,40 @@ struct MainWindow : public winrt::Microsoft::UI::Xaml::WindowT<MainWindow>
public:
MainWindow()
{
mNav.Header(winrt::box_value(L"Header"));
mNav.Header(winrt::box_value(L"CMake, C++/WinRT, and WinUI 3 Demo App"));
mNav.Content(mContent);
mNav.IsSettingsVisible(false);

muxc::NavigationViewItem item1;
item1.Content(winrt::box_value(L"Item 1"));
item1.Icon(muxc::SymbolIcon(muxc::Symbol::Play));

mNav.MenuItems().Append(item1);
// This fails due to Microsoft.UI.Xaml.Controls.XamlControlResources not
// being loaded, but loading it fails :(

muxc::NavigationViewItem item2;
item2.Content(winrt::box_value(L"Item 2"));
item2.Icon(muxc::SymbolIcon(muxc::Symbol::Copy));
mNav.MenuItems().Append(item2);

muxc::NavigationViewItem item3;
item3.Content(winrt::box_value(L"Item 3"));
item3.Icon(muxc::SymbolIcon(muxc::Symbol::Paste));
mNav.MenuItems().Append(item3);

mNav.IsSettingsVisible(true);

Content(mNav);
}
};

struct MyApp : public winrt::Microsoft::UI::Xaml::ApplicationT<MyApp>
struct MyApp : public winrt::Microsoft::UI::Xaml::ApplicationT<MyApp, winrt::Microsoft::UI::Xaml::Markup::IXamlMetadataProvider>
{
private:
winrt::Microsoft::UI::Xaml::XamlTypeInfo::XamlControlsXamlMetaDataProvider mXamlControlsMetaDataProvider;

public:
MyApp()
{
::winrt::Windows::Foundation::Uri resourceLocator{ L"ms-appx:///App.xaml" };
::winrt::Windows::Foundation::Uri resourceLocator{L"ms-appx:///App.xaml"};
::winrt::Microsoft::UI::Xaml::Application::LoadComponent(*this, resourceLocator);

UnhandledException([this](IInspectable const &, winrt::Microsoft::UI::Xaml::UnhandledExceptionEventArgs const &e)
Expand All @@ -58,6 +73,23 @@ struct MyApp : public winrt::Microsoft::UI::Xaml::ApplicationT<MyApp>
// ... if it werent' for that exception, I'd add it to `Resources()` here
winrt::make<MainWindow>().Activate();
}

winrt::Microsoft::UI::Xaml::Markup::IXamlType
GetXamlType(const winrt::hstring& fullName)
{
return mXamlControlsMetaDataProvider.GetXamlType(fullName);
}

winrt::Microsoft::UI::Xaml::Markup::IXamlType
GetXamlType(const winrt::Windows::UI::Xaml::Interop::TypeName& type)
{
return mXamlControlsMetaDataProvider.GetXamlType(type);
}

winrt::com_array<winrt::Microsoft::UI::Xaml::Markup::XmlnsDefinition> GetXmlnsDefinitions()
{
return mXamlControlsMetaDataProvider.GetXmlnsDefinitions();
}
};

int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine, int nCmdShow)
Expand Down

0 comments on commit 8a8539a

Please sign in to comment.