|
| 1 | +#include "pch.h" |
| 2 | +#include "XamlApplication.h" |
| 3 | +#include "XamlApplication.g.cpp" |
| 4 | + |
| 5 | +#include "winrt/Microsoft.UI.Xaml.XamlTypeInfo.h" |
| 6 | + |
| 7 | +namespace winrt::Microsoft::ReactNative::implementation |
| 8 | +{ |
| 9 | +using namespace ::winrt::Microsoft::UI::Xaml; |
| 10 | +using namespace ::winrt::Microsoft::UI::Xaml::Markup; |
| 11 | +using namespace ::winrt::Windows::UI::Xaml::Interop; |
| 12 | + XamlApplication::XamlApplication() |
| 13 | + { |
| 14 | + //m_providers.push_back(winrt::make_self<XamlMetaDataProvider>().as<winrt::Microsoft::UI::Xaml::Markup::IXamlMetadataProvider>()); |
| 15 | + s_current = *this; |
| 16 | + |
| 17 | + // TODO: It's probably not a good idea to only load the controls pri file, there are other ones too. |
| 18 | + auto resourceManager = |
| 19 | + winrt::Microsoft::Windows::ApplicationModel::Resources::ResourceManager(L"Microsoft.UI.Xaml.Controls.pri"); |
| 20 | + |
| 21 | + this->ResourceManagerRequested([resourceManager](auto &&, ResourceManagerRequestedEventArgs args) { |
| 22 | + args.CustomResourceManager(resourceManager); |
| 23 | + }); |
| 24 | + winrt::Microsoft::UI::Xaml::Hosting::WindowsXamlManager::InitializeForCurrentThread(); |
| 25 | + |
| 26 | + m_providers.push_back( |
| 27 | + winrt::make_self<XamlMetaDataProvider>() |
| 28 | + .as<winrt::Microsoft::UI::Xaml::Markup::IXamlMetadataProvider>()); // Default generated provider |
| 29 | + m_providers.push_back(winrt::Microsoft::UI::Xaml::XamlTypeInfo::XamlControlsXamlMetaDataProvider()); |
| 30 | + |
| 31 | + auto winUIResources = winrt::Microsoft::UI::Xaml::Controls::XamlControlsResources(); |
| 32 | + Resources().MergedDictionaries().Append(winUIResources); |
| 33 | + } |
| 34 | + |
| 35 | + XamlApplication::~XamlApplication() |
| 36 | + { |
| 37 | + s_current = nullptr; |
| 38 | + } |
| 39 | + |
| 40 | + void XamlApplication::AddMetadataProvider(winrt::Microsoft::UI::Xaml::Markup::IXamlMetadataProvider const& otherProvider) |
| 41 | + { |
| 42 | + m_providers.push_back(otherProvider); |
| 43 | + } |
| 44 | + |
| 45 | + winrt::Microsoft::UI::Xaml::Markup::IXamlType XamlApplication::GetXamlType(winrt::Windows::UI::Xaml::Interop::TypeName const& type) |
| 46 | + { |
| 47 | + for (auto &&provider : m_providers) { |
| 48 | + if (auto result = provider.GetXamlType(type)) { |
| 49 | + return result; |
| 50 | + } |
| 51 | + } |
| 52 | + return nullptr; |
| 53 | + } |
| 54 | + |
| 55 | + winrt::Microsoft::UI::Xaml::Markup::IXamlType XamlApplication::GetXamlType(hstring const& fullName) |
| 56 | + { |
| 57 | + for (auto &&provider : m_providers) { |
| 58 | + if (auto result = provider.GetXamlType(fullName)) { |
| 59 | + return result; |
| 60 | + } |
| 61 | + } |
| 62 | + |
| 63 | + return nullptr; |
| 64 | + } |
| 65 | + com_array<winrt::Microsoft::UI::Xaml::Markup::XmlnsDefinition> XamlApplication::GetXmlnsDefinitions() |
| 66 | + { |
| 67 | + std::vector<::winrt::Microsoft::UI::Xaml::Markup::XmlnsDefinition> allDefinitions; |
| 68 | + for (const auto &provider : m_providers) { |
| 69 | + auto definitionsCurrentProvider = provider.GetXmlnsDefinitions(); |
| 70 | + for (const auto &definition : definitionsCurrentProvider) { |
| 71 | + allDefinitions.insert(allDefinitions.begin(), definition); |
| 72 | + } |
| 73 | + } |
| 74 | + return winrt::com_array<::winrt::Microsoft::UI::Xaml::Markup::XmlnsDefinition>( |
| 75 | + allDefinitions.begin(), allDefinitions.end()); |
| 76 | + } |
| 77 | + |
| 78 | + winrt::Microsoft::ReactNative::XamlApplication XamlApplication::s_current{nullptr}; |
| 79 | +} |
0 commit comments