CsWinRT icon indicating copy to clipboard operation
CsWinRT copied to clipboard

Projection of [bindable] attribute

Open brabebhin opened this issue 2 years ago • 1 comments

Hi,

I have some IDL file which contains some classes which are defined as [bindable]. When I try to generate the bindings for said IDL file for .net 6, it will generate stuff with

[global::Windows.UI.Xaml.Data.Bindable]

And then proceed to complain that Windows.UI.Xaml does not exist.

How do I fix this? Thanks.

brabebhin avatar Sep 11 '22 16:09 brabebhin

@brabebhin, this looks to be the UWP version which we do not distribute a C#/WinRT projection for. We only distribute one for the WinAppSDK / WinUI version of it. Is your component a UWP component or a WinAppSDK / WinUI component? If it is the latter, I would expect it to get generated as Microsoft.UI.Xaml.Data.Bindable and work.

manodasanW avatar Sep 12 '22 18:09 manodasanW

@brabebhin and me have a C++/WinRT component library that works with both UWP and WinUI. DesktopCompatible is set. For UWP, out library can be used directly, no need for CsWinRT. For .NET Core/WinUI, we generate the wrappers with CsWinRT.

The bindable attribute is only needed to allow data binding for C++/CX clients. It is not needed at all for C#. So I wonder why the attribute is added at all by CsWinRT. It could just be omitted. And if it is mapped, then I'd rather expect it to map to Microsoft.UI.Xaml.Data.Bindable attribute than to the legacy UWP attribute.

lukasf avatar Oct 24 '22 19:10 lukasf

I would expect csWinRT to generate the projection based on the project type that consumes it (i.e. if it installed in a winUI project, I'd expect it to generate the winUI compatible projection of whatever dll).

Keep in mind that winRT (not to be confused with UWP) can be used by both desktop (in the classic sense - mfc, winforms, WPF, directX whatever), winUI and UWP.

brabebhin avatar Oct 24 '22 19:10 brabebhin

Anyway, we fixed this with conditional compilation within the winRT component. It would have been nice to have this handled by the various /winrt tools involved.

brabebhin avatar Oct 25 '22 07:10 brabebhin