Replies: 1 comment 1 reply
-
|
You may be interested in IXamlType: https://learn.microsoft.com/en-us/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.markup.ixamltype?view=windows-app-sdk-1.6 Behind the scenes, the XAML compiler automatically generates the supporting code.” Usage // =====================
// Get XAML type from the current App's MetadataProvider
// =====================
if (auto app = Application::Current())
{
if (auto provider = app.try_as<winrt::Microsoft::UI::Xaml::Markup::IXamlMetadataProvider>())
{
winrt::Windows::UI::Xaml::Interop::TypeName name =
winrt::xaml_typename<YourControl>();
if (winrt::Microsoft::UI::Xaml::Markup::IXamlType xamlType = provider.GetXamlType(name))
{
auto instance = xamlType.ActivateInstance();
}
}
}
// =====================
// Get XAML type from a third-party component
// (XamlToolkit Labs for WinUI's MetadataProvider)
// =====================
// Requires <winrt/winrt::XamlToolkit::Labs::WinUI.h>
auto provider = winrt::XamlToolkit::Labs::WinUI::XamlMetaDataProvider();
winrt::Windows::UI::Xaml::Interop::TypeName name =
winrt::xaml_typename<winrt::XamlToolkit::Labs::WinUI::MarkdownTextBlock>();
if (winrt::Microsoft::UI::Xaml::Markup::IXamlType xamlType = provider.GetXamlType(name))
{
auto instance = xamlType.ActivateInstance();
} |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment

Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello, does anyone know how to instantiate a locally defined class by its name (or
TypeName), in C++/WinRT, in an unpackaged/unregistered application? And preferably without using manifest-based activation.winrt::get_activation_factorydoesn't seem to work.I feel like this is possible, though, because I've successfully passed a locally defined
Pagetypename toMicrosoft::UI::Xaml::Controls::Frame::Navigate, and it doesn't have any trouble instantiating thePage-derived class. So I'm wondering how theFrameis activating thePagebehind the scenes.Thanks for any info.
Beta Was this translation helpful? Give feedback.
All reactions