Reflection
not support custom xaml control
#12858
Replies: 1 comment 2 replies
-
trailed some times, I find the reason. The compiler will generate a var appProviderProperty = this.GetType().GetProperty("_AppProvider", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
var appProvider = appProviderProperty!.GetValue(this)!;
var appProviderProviderProperty = appProvider.GetType().GetProperty("Provider", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
var appProviderProvider = appProviderProviderProperty!.GetValue(appProvider);
var othersProperty = appProviderProvider!.GetType().GetProperty("OtherProviders", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
var otherProviders = othersProperty!.GetValue(appProviderProvider) as List<Microsoft.UI.Xaml.Markup.IXamlMetadataProvider>;
var originType = Assembly.Load("MyAssembly").GetType("MyAssembly.MyAssembly_XamlTypeInfo.XamlMetaDataProvider");
var provider = Activator.CreateInstance(originType!) as Microsoft.UI.Xaml.Markup.IXamlMetadataProvider;
otherProviders!.Add(provider!); Is it possible to provide a frendly way to do it in future? |
Beta Was this translation helpful? Give feedback.
2 replies
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.
-
Current behavior
I have a custom class named
BasePage
(empty class) which inherited thePage
class, and another class namedMainPage
inherited theBasePage
, when i create a instance ofMainPage
by reflection,i got a error: Microsoft.UI.Xaml.Markup.XamlParseException:“XAML parsing failed.”, but if i refer the project which theMainPage
in,and reflect it or create it bynew
,it works.Works on UWP/WinUI
None
Environment
Uno.WinUI / Uno.WinUI.WebAssembly / Uno.WinUI.Skia
Affected platforms
Windows
IDE
Visual Studio 2022
Beta Was this translation helpful? Give feedback.
All reactions