lundi 28 juin 2021

Error creating a page (XAML) at runtime from an assembly in WinUi (desktop)

I have two projects for WinUI 3 (Desktop). One project is a desktop app and the other project is a class library (for desktop app). In the library I would like to define a page in XAML and load it into the desktop app at runtime (plug-in concept). The library is called 'MyHome.dll'. A page is defined there in XAML. The class for the page is called 'MyHome'.

The code for loading the assembly:

var dir = System.AppDomain.CurrentDomain.BaseDirectory;
Assembly MyHomeAssembly = Assembly.LoadFile (dir + "/MyHome.dll");
var page = (Page) Assembly.CreateInstance ("MyHome.MyHome")

The assembly is loaded. With the debugger I can see that the class 'MyHome' is included. A XAML parsing error is generated. My question: How do I load a Page (XAML) and the code C #) from a class at runtime.





Aucun commentaire:

Enregistrer un commentaire