与我之前提出的这个问题相关,我想知道是否也可以动态加载与 XAML 文件配对的代码隐藏文件。它可以以这种方式工作还是将两者都编译成DLL会更好?
谢谢!
Actually, it's the code-behind that loads the XAML file. The designer generates a hidden file that binds all of your named elements and events to the class. (Notice the 'partial' keyword on your class in the code-behind.) It functions similar to the file that the WinForms designer generates, only it's a bit harder to find. You can find them in the "obj/debug/" folder along with the compiled BAML.
As for actually answering your quetion, it would be better to compile them to a DLL. It may not be impossible to set up a library that can connect a XAML to a special class that has methods to dynamically access elements, but there's nothing like that now as far as I know.