[Bug][WinUI]: ViewModelViewHost not working on WinUI projects.
Describe the bug 🐞
ViewModelViewHost not working on WinUI projects. When I bind a ObservableCollection<TestUserControlViewModel> to a ListView, an XamlParseException occurs with following message:
Exception thrown: 'Microsoft.UI.Xaml.Markup.XamlParseException' in WinRT.Runtime.dll WinRT information: The type 'ViewModelViewHost' was not found because 'clr-namespace:ReactiveUI;assembly=ReactiveUI.WinUI' is an unknown namespace. [Line: 1 Position: 276] XAML parsing failed.
Currently I use ViewModelViewHost directly in my DataTemplate to resolve this temporary.
Step to reproduce
I create a simple project to reproduce this:
Reproduction repository
https://github.com/reactiveui/ReactiveUI
Expected behavior
Get the view rendered by the view model.
Screenshots 🖼️
No response
IDE
Visual Studio 2022
Operating system
Windows
Version
10.0.22000.652
Device
Surface Book 2
ReactiveUI Version
18.0.10
Additional information ℹ️
No response
WinUI has other namespace declarations. Try xmlns:rx="using:ReactiveUI"
@HavenDV Hi, I encountered the same issue and do not understand your suggestion. As far as I understand, the data template is generated at runtime by reactive ui and there is no way to influence the generation. See AutoDataTemplateBindingHook.cs @lighterhy workaround does work.
I've failed to find any documentation whether clr-namespace is supported in winui or not - the official documentation for wpf does mention it, the one for uwp doesn't.
I think, this is indeed a bug and needs to be fixed in ReactiveUI.
I can confirm this as well. Just giving a ListView a name and binding to its ItemsSource in the code-behind produces an XAML parsing error, but if I give it a DataTemplate containing nothing but a ViewModelViewHost with its ViewModel property set to {x:Bind}, everything works fine.
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.