CsWinRT
CsWinRT copied to clipboard
Projection of [bindable] attribute
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, 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.
@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.
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.
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.