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 Pathless Casting (this) references cause source generator error #7893

Closed
hawkerm opened this issue Jan 23, 2022 · 4 comments · Fixed by #10013
Closed

x:Bind Pathless Casting (this) references cause source generator error #7893

hawkerm opened this issue Jan 23, 2022 · 4 comments · Fixed by #10013
Labels
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

@hawkerm
Copy link

hawkerm commented Jan 23, 2022

Current behavior

Was using pathless casting in UWP data template to bind to the 'this' object of the data template:

<DataTemplate x:DataType="local:SomeTypeName">
  <local:MyControl MyProperty="{x:Bind (local:SomeTypeName)}"/>
</DataTemplate>

This gave me the following error when trying to run in WASM:

Uno.UI.SourceGenerators.XamlGenerator.XamlCodeGenerator\MainPage_bf38630c1c1d5b8ecc552685d35228f7.cs(914,322,914,324): error CS7000: Unexpected use of an aliased name

Switching out to old-style {Binding} syntax allowed me to compile.

Expected behavior

Should accept the pathless casting syntax for x:Bind.

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

No response

Workaround

Switch x:Bind pathless cast to Binding if only doing direct. Not sure if there's the same issue for function binding which I'm not sure how you'd work around.

Works on UWP/WinUI

Yes

Environment

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

NuGet package version(s)

4.0.11

Affected platforms

WebAssembly

IDE

Visual Studio 2022

IDE version

17.0.5

Relevant plugins

No response

Anything else we need to know?

No response

@hawkerm hawkerm 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 Jan 23, 2022
@jeromelaban
Copy link
Member

Thanks for the report! Would you have the exact type that was bound? We're looking for an exact repro, as previous ones we got were not successful.

@jeromelaban jeromelaban added 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 labels Jan 24, 2022
@hawkerm
Copy link
Author

hawkerm commented Feb 7, 2022

It's my own type implemented in my project:

public partial class MyClass : ObservableObject
{

With a couple of simple properties (string and custom enum), nothing more.

It is being built using the new MVVM Toolkit source generators (initially V1, now V2), so maybe there's a conflict between the two source generators somehow? (If you're not seeing it with regular types?)

Though I tried switching it to a regular ObservableObject without the partial class and think I'm still getting the same message. So it may not be related.

If I remove the pathless cast to the whole type, and instead use a specific property, then I don't get the error message.

@jeromelaban
Copy link
Member

Thanks for the update! Yes it may seem that the parser is not handling this very well.

Note for contributors

This is the location of the parser tests:

public class Given_XBindRewriter
{
[TestMethod]
// DataTemplates (with context)
[DataRow("ctx", "MyProperty.A", "ctx.MyProperty.A")]
[DataRow("ctx", "MyProperty", "ctx.MyProperty")]
[DataRow("ctx", "MyStaticProperty", "MyStaticProperty")]
[DataRow("ctx", "MyStaticMethod()", "MyStaticMethod()")]
[DataRow("ctx", "MyProperty.A.ToLower()", "ctx.MyProperty.A.ToLower()")]
[DataRow("ctx", "System.String.Format('{0:X8}', a.Value)", "System.String.Format('{0:X8}', ctx.a.Value)")]
[DataRow("ctx", "Static.MyFunction(42.0)", "Static.MyFunction(42.0)")]
[DataRow("ctx", "Static.MyFunction(true)", "Static.MyFunction(true)")]
[DataRow("ctx", "Static.MyFunction(MyProperty)", "Static.MyFunction(ctx.MyProperty)")]
[DataRow("ctx", "MyNameSpace.Static2.MyProperty", "MyNameSpace.Static2.MyProperty")]
[DataRow("ctx", "MyNameSpace.Static2.MyEnum.EnumMember", "MyNameSpace.Static2.MyEnum.EnumMember")]
[DataRow("ctx", "MyNameSpace.Static2.MyProperty.ToArray()", "MyNameSpace.Static2.MyProperty.ToArray()")]
[DataRow("ctx", "MyNameSpace.Static2.MyFunction(MyProperty)", "MyNameSpace.Static2.MyFunction(ctx.MyProperty)")]
[DataRow("ctx", "MyFunction(MyProperty)", "ctx.MyFunction(ctx.MyProperty)")]
[DataRow("ctx", "", "ctx")]
[DataRow("ctx", "(FontFamily)a.Value", "(FontFamily)ctx.a.Value")]
[DataRow("ctx", "(global::System.Int32)a.Value", "(global::System.Int32)ctx.a.Value")]

@MartinZikmund MartinZikmund added 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 Mar 4, 2022
@michael-hawker
Copy link

michael-hawker commented Sep 23, 2022

I think this is for any types of parentheses; so not just pathless casting, but for attached properties as well (i.e. uno only looking for function and casting scenarios):

"{x:Bind AdornerCanvas.(labs:FrameworkElementExtensions.ActualWidth), Mode=OneWay}"

Hit above in labs trying to use our helpers in the Toolkit for size binding.

From the official docs, see https://learn.microsoft.com/windows/uwp/xaml-platform/x-bind-markup-extension#attached-properties

Text="{x:Bind Button22.(Grid.Row)}"

The xBind markup extension is a high performance alternative to Binding. xBind - new for Windows 10 - runs in less time and less memory than Binding and supports better debugging.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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

Successfully merging a pull request may close this issue.

4 participants