Open sotanakamura opened 1 year ago
As it is, the application does implement IXamlMetadataProvider. This is defined in the generated C++ file for the app class. Furthermore, as I understand it, IXamlMetadataProvider must be able to return full type information, including callbacks to get or set properties by name, for every type used in XAML in your application. If it doesn’t, those types will not be usable from XAML as then WinUI will have no idea how to configure the object used to match the values in the XAML. If you do as you describe, then you may end up being unable to use any types defined in your project from XAML, including code-behinds; the only types you could successfully use are the ones supported by XamlControlsXamlMetaDataProvider
. Of course there is no documentation for any of this.
IXamlMetadataProvider and the objects it returns are how the C++-based WinUI 3 core library is able to manipulate objects implemented in any programming language. (C++ types call through to other C++ code, C# types go through a CCW and are handled in managed code, and so on.) You could use these APIs to create your own type metadata system, which unfortunately is intended to be used only when you are porting a new language to WinRT. It is assumed that C# and C++ developers would always use the built-in system, and that the built-in system would be sufficient for all cases.
In short, your proposed change would actually cause widespread breakage (as far as I can tell). Sorry about that!
Thank you for providing a lot of information. Actually, I want to create WinUI 3 apps without XAML and use IXamlMetadataProvider only for instantiating XamlControlsResources. If we can instantiate XamlControlsResources without XAML integration, it would be nice.
While I understand what you are going for here, I think the better option would be for Microsoft to document how it works and provide a sample. Interestingly, the Xaml Islands application that you referenced is close to what you would need for this to work normally. Here is a repository that shows this at work. This should be extensible to a certain extent, where if you have a custom control that also provides a metadata provider then these controls can also be used.
Thank you for providing the implementation. I updated the issue info with your code.
I updated the sample code with Kenny Kerr's implementation.
Proposal: XamlApplication: Application implementing IXamlMetadataPorvider interface
Summary
XamlApplication is a Application implementing IXamlMetadataProvider interface and loading WinUI theme. This API provides an easy way to create an application integrating XAML.
Rationale
Scope
Important Notes
This API was proposed by @Scottj1s in Meet C++/WinRT 2.0: Faster and smarter in the open - BRK4009.
The sample code implemented by Kenny Kerr.