ReactiveUI icon indicating copy to clipboard operation
ReactiveUI copied to clipboard

[Bug][WinUI]: ViewModelViewHost not working on WinUI projects.

Open lighterhy opened this issue 3 years ago • 1 comments

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:

App1.zip

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

lighterhy avatar Apr 30 '22 03:04 lighterhy

WinUI has other namespace declarations. Try xmlns:rx="using:ReactiveUI"

HavenDV avatar Jul 04 '22 04:07 HavenDV

@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.

Gitii avatar Mar 27 '23 15:03 Gitii

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.

jdcrutchley avatar May 17 '23 23:05 jdcrutchley

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.

github-actions[bot] avatar Jul 23 '23 00:07 github-actions[bot]