Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x:Bind not support the property generated by source generator #14409

Open
SongOfYouth opened this issue Nov 14, 2023 · 5 comments
Open

x:Bind not support the property generated by source generator #14409

SongOfYouth opened this issue Nov 14, 2023 · 5 comments
Labels
area/code-generation Categorizes an issue or PR as relevant to code generation area/xBind 🪢 Categorizes an issue or PR as relevant to x:Bind difficulty/medium 🤔 Categorizes an issue for which the difficulty level is reachable with a good understanding of WinUI kind/bug Something isn't working project/binding 🪢 Categorizes an issue or PR as relevant to the binding engine

Comments

@SongOfYouth
Copy link

SongOfYouth commented Nov 14, 2023

Current behavior

I have generated the property via IIncrementalGenerator source generator like this:
image

and bind it in the xaml file:
image

then build, it comes out:

D:\Dysoft\Git\HIS3.0\Busi\Base\Dy.Base.UI\Uno.UI.SourceGenerators\Uno.UI.SourceGenerators.XamlGenerator.XamlCodeGenerator\DictionaryTypePage_08d21259fdf0d2994045384693412e24.cs(111,407,111,605): error CS0029: Cannot implicitly convert type 'Dy.Base.UI.ViewModels.DictionaryTypeItemViewModel' to 'string'

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

No response

NuGet package version(s)

No response

Affected platforms

No response

IDE

Visual Studio 2022

IDE version

No response

Relevant plugins

No response

Anything else we need to know?

What i have bound to the Text of TextBox is property Code, but the error points to the ViewModel type converting fail.

@SongOfYouth SongOfYouth added difficulty/tbd Categorizes an issue for which the difficulty level needs to be defined. kind/bug Something isn't working triage/untriaged Indicates an issue requires triaging or verification labels Nov 14, 2023
@MartinZikmund MartinZikmund added area/code-generation Categorizes an issue or PR as relevant to code generation area/xBind 🪢 Categorizes an issue or PR as relevant to x:Bind project/binding 🪢 Categorizes an issue or PR as relevant to the binding engine difficulty/medium 🤔 Categorizes an issue for which the difficulty level is reachable with a good understanding of WinUI and removed triage/untriaged Indicates an issue requires triaging or verification difficulty/tbd Categorizes an issue for which the difficulty level needs to be defined. labels Nov 14, 2023
@jeromelaban
Copy link
Member

Thanks for the report. It seems that the code you're referencing is coming from a Source Generator. This is currently not supported because of #12073, which is ultimately caused by dotnet/roslyn#57239.

If you need this to work, you'll need to place your ViewModel classes in a separate library project from the XAML files.

@SongOfYouth
Copy link
Author

Thanks for the report. It seems that the code you're referencing is coming from a Source Generator. This is currently not supported because of #12073, which is ultimately caused by dotnet/roslyn#57239.

If you need this to work, you'll need to place your ViewModel classes in a separate library project from the XAML files.

I think so too.but problem is the same code which from mvvmtoolkit source generator works well...

[ObeservaleProperty]
string _code;

@jeromelaban
Copy link
Member

jeromelaban commented Nov 15, 2023

It works with MVVM Toolkit because Uno has a specific workaround for this library. It does not know about the other generators and can't generate code properly.

@Youssef1313
Copy link
Member

Best that can be done here is separating out the ViewModels to a separate project, if possible.

That way, the source generator will be run in the context of a project different than the one XAML generator runs in and things will work. I don't think this is currently fixable.

@Youssef1313
Copy link
Member

Another possible workaround is also suggested in #12073 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/code-generation Categorizes an issue or PR as relevant to code generation area/xBind 🪢 Categorizes an issue or PR as relevant to x:Bind difficulty/medium 🤔 Categorizes an issue for which the difficulty level is reachable with a good understanding of WinUI kind/bug Something isn't working project/binding 🪢 Categorizes an issue or PR as relevant to the binding engine
Projects
None yet
Development

No branches or pull requests

4 participants