uno icon indicating copy to clipboard operation
uno copied to clipboard

Unable to use binding on XAML files with code-behind missing a base type

Open HavenDV opened this issue 4 years ago • 7 comments

Current behavior

<views:StatusView DataContext="{Binding StatusViewModel}" />

WASM(maybe other) show this error:

error CS1061: 'DependencyObject' does not contain a definition for 'SetBinding' and no accessible extension method 'SetBinding' accepting a first argument of type 'DependencyObject' could be found (are you missing a using directive or an assembly reference?)

Expected behavior

No response

How to reproduce it (as minimally and precisely as possible)

No response

Workaround

No response

Works on UWP/WinUI

Yes

Environment

Uno.UI / Uno.UI.WebAssembly / Uno.UI.Skia

NuGet package version(s)

3.12.0-dev.2

Affected platforms

WebAssembly

IDE

Visual Studio 2022

IDE version

preview 7.0

Relevant plugins

No response

Anything else we need to know?

No response

HavenDV avatar Oct 31 '21 05:10 HavenDV

Thanks for the report. Can you provide a sample repro for this issue? DataContext binding is supported, but you may have hit an edge case.

jeromelaban avatar Oct 31 '21 20:10 jeromelaban

Sure. Sorry, I was not able to repeat this in a clean Uno project, but remove all unnecessary from this. ratbuddyssey-datacontextbug (1).zip

HavenDV avatar Nov 01 '21 00:11 HavenDV

Thanks for the repro.

This is not a behavior we'll be able to fix in Uno, as the type in question is not known during the XAML generation (it is generated by another generator). This will be the case until there's a way in Source Generators to define dependencies or multiple passes.

The only way to work around this is to make the base type known explicitly (e.g. in FileView, specifiy an actual base type).

jeromelaban avatar Nov 03 '21 15:11 jeromelaban

I think it's not about the generator. I was able to reproduce this in another project where I am not using other generators: H.ReactiveUI.CommonInteractions-master.zip

HavenDV avatar Nov 04 '21 11:11 HavenDV

The issue is this time caused by the fact that there's no explicit base class defined on the class PreviewDropView. Uno does not support this yet.

jeromelaban avatar Nov 04 '21 12:11 jeromelaban

The first reproduction, by the way, defines the ViewBase classes inside the .Net Standard library, so this shouldn't be a problem either. This should work even if the code behind files are empty.

HavenDV avatar Nov 04 '21 12:11 HavenDV

It should indeed. The workaround is to add the base type explicitly in the code-behind file.

jeromelaban avatar Nov 04 '21 13:11 jeromelaban