ericsink / SwiftWinRT

WinRT Bridging for Swift
BSD 3-Clause "New" or "Revised" License
45 stars 1 forks source link

Some UI controls just crash #3

Open ericsink opened 2 years ago

ericsink commented 2 years ago

The XamlApp sample is a place where I experiment with support for various WinUI controls.

Controls that work:

Controls that crash:

MouriNaruto commented 1 year ago

You can refer https://github.com/CommunityToolkit/Microsoft.Toolkit.Win32/tree/master/Microsoft.Toolkit.Win32.UI.XamlApplication to implement a WinRT object inherited from Windows.UI.Xaml.Application.

After you implement this object, you can initialize the WinRT XAML via create instance of this object after initializing the COM.

I have made a XAML Islands based toolchain called Mile.Xaml. Here is the Mile.Xaml.Application object implementation: https://github.com/ProjectMile/Mile.Xaml/tree/main/Mile.Xaml. Here is the Mile.Xaml BlankApp example: https://github.com/ProjectMile/Mile.Xaml.Samples/blob/main/MileXamlBlankApp/WinMain.cpp

I hope these XAML Islands related information can help you. Something may be similar for WinUI 3.

Kenji Mouri

driver1998 commented 1 year ago

Looks like you can get pretty far if you just load app.xaml as-is in runtime and implementing IXamlMetadataProvider by forwarding to Microsoft.UI.Xaml.XamlTypeInfo.XamlControlsXamlMetaDataProvider

This is C# but I guess Swift will behave similarly.

image

driver1998 commented 1 year ago

See https://github.com/driver1998/WinUIMinimalXaml for the demo code. (credit goes to @sylveon)