AvaloniaUI / Avalonia

Develop Desktop, Embedded, Mobile and WebAssembly apps with C# and XAML. The most popular .NET UI client technology
https://avaloniaui.net
MIT License
25.22k stars 2.18k forks source link

Possible Interop Story WinRT #4045

Open AngelMunoz opened 4 years ago

AngelMunoz commented 4 years ago

Hi everyone Is it possible to implement the IInitializeWithWindow and IWindowNative with an Avalonia Application? sample here https://github.com/microsoft/WinUI-3-Demos/tree/master/DemoBuildCs/DemoBuildCs/DemoBuildCs I was doing some experimentation with the C#/WinRT projection Microsoft released in past weeks while I could make UI-less APIs work (samples here https://github.com/AngelMunoz/WinRTFs) I was wondering if it's possible to do something like that in an Avalonia App, that could allow Avalonia apps to have some degree of integration with the system like camera UI's User activities, file/folder pickers, auth dialogs, and some other nice stuff, I have this comment for context https://github.com/microsoft/CsWinRT/issues/287#issuecomment-632391358

Copied from Gitter

kekekeks commented 4 years ago

@jkoritzinsky It seems that WinRT interop doesn't actually require us retargeting to .NET Core. Am I missing something?

kekekeks commented 4 years ago

Some relevant links: https://github.com/dotnet/runtime/pull/36715 https://github.com/microsoft/CsWinRT

jkoritzinsky commented 4 years ago

For our usage, we should be able to swing targeting .NET Standard 2.0 as long as we use the Microsoft.Windows.Sdk.Net package. However, that package is a bit large, so it might be worth multi targeting.

AngelMunoz commented 4 years ago

For our usage, we should be able to swing targeting .NET Standard 2.0 as long as we use the Microsoft.Windows.Sdk.Net package. However, that package is a bit large, so it might be worth multi targeting.

I think that was the prior way to target WinRT, the projection seems that's the new and recommended way to do so as mentioned on the PR above, the projection will target netstandard2.0 as well as .net5 when it comes out, not sure what will happen to the sdks though

jkoritzinsky commented 4 years ago

The old way was to use the Microsoft.Windows.Sdk.Contracts package. The Microsoft.Windows.Sdk.NET package is the new way. We should not be running CsWinRT directly.

AngelMunoz commented 3 years ago

hi @jkoritzinsky sorry to bother I saw this comment https://github.com/microsoft/CsWinRT/issues/355#issuecomment-692189898

CsWinRT now supports ComImport-attributed interfaces directly.

I've tried to check samples about the IInitializeWindow interface but to be honest I always feel quite lost.

In short is this something that we can achieve in Avalonia right now? or are we still limited in some way

jkoritzinsky commented 3 years ago

Possibly. The ComImport support is primarily around consuming a native type via the ComImport interfaces, not writing a type that uses them.