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

Visual Studio 2022 v17.12 breaks binding to [ObservableProperty] #76470

Closed
bjorn-malmo opened this issue Dec 17, 2024 · 9 comments
Closed

Visual Studio 2022 v17.12 breaks binding to [ObservableProperty] #76470

bjorn-malmo opened this issue Dec 17, 2024 · 9 comments

Comments

@bjorn-malmo
Copy link

Version Used:

Building the application using Visual Studio 2022 v17.12.x breaks Binding to [ObservableProperty]
Building the application using Visual Studio 2022 v17.10.6 works perfectly

Please see original issue:
CommunityToolkit/dotnet#1011

Steps to Reproduce:

  1. Project PropertyBindingTest.sln in repo https://github.com/bjorn-malmo/bug-free-happiness/.
  2. Build and run on Visual Studio 2022 v17.12.x
  3. Note that the Binding to ObservableProperty on object deriving from Control is not updated
  4. However, running the same application in Visual Studio 2022 v17.10.6 works

A minimal repro, with source-code provided, is ideal. Most compiler/language issues can be distilled into a snippet that can be pasted into sharplab.

Diagnostic Id:

If this is a report about a bug in an analyzer, please include the diagnostic ID and message if possible (e.g. "IDE0030: Use coalesce expression").

Expected Behavior:
Binding updating value in UI

Actual Behavior:
Binding not updating UI value for property

@CyrusNajmabadi
Copy link
Member

What do you mean by "breaks binding"?

@bjorn-malmo
Copy link
Author

The binding will not update as a result of a PropertyChanged event notification. The issue has been reproduced by CommunityToolkit (see linked issue above), but closed as it is not deemed a problem in CommunityToolkit, but probably something with code generation, as the UI will update if the program is run in older Visual Studio 2022, but not in the latest version.

@CyrusNajmabadi
Copy link
Member

Again, I don't know what "breaks binding" means.

@CyrusNajmabadi
Copy link
Member

The binding will not update as a result of a PropertyChanged event notification

I don't know what this means. What event notification are you referring to? What is a "binding" here?

but probably something with code generation,

What code generation?

if the program is run in older Visual Studio 2022, but not in the latest version.

What code was generated in older versions of visual studio, and what code is now generated in the latest version?

@bjorn-malmo
Copy link
Author

OK, I'll try to explain in a different way:

  1. Create a WinUI 3 Custom Control
  2. Using CommunityToolkit, attribute the class [ObservableObject]
  3. Create a field and attribute it [ObservableProperty]
  4. In the control's template, bind to the property. Text="{Binding MyValue, RelativeSource={RelativeSource TemplatedParent}}" (In this situation, x:Bind cannot be used, right?)
  5. Update the value of the MyValue property. In the sample I use a RelayCommand

Sample application found here: Project PropertyBindingTest.sln in repo https://github.com/bjorn-malmo/bug-free-happiness/

Now, compile the application using Visual Studio 2022 v17.10

Run the application, update the value of the MyValue property and watch the UI display the new value in the text property.

In this situation, I consider the "Binding" to be working!

Update Visual Studio 2022 to v17.12

Run the same application again, update the value of the MyValue property, and watch the UI not responding to the update. The PropertyChanged event is raised however.

In this situation, I consider the "Binding" to be broken! I don't know what is broken, but it doesn't work. No update. No change.

Screenshot from application run in older version:
Image

Image

Screenshot from application run in new version:

Image

Note the text block on top clearly saying Initial value in the bottom most image!

@CyrusNajmabadi
Copy link
Member

Why do you think this is Roslyn? We are the c# to IL compiler. What is different between the two compiled programs that is causing the issue here?

@CyrusNajmabadi
Copy link
Member

In the control's template, bind to the property. Text="{Binding MyValue, RelativeSource={RelativeSource TemplatedParent}}" (In this situation, x:Bind cannot be used, right?)

This appears to be some different language, unrelated to c#/vb. Perhaps an issue with that language, or whatever ui toolkit you are using?

@huoyaoyuan
Copy link
Member

This is WinUI xaml compiler and belongs to https://github.com/microsoft/microsoft-ui-xaml

@CyrusNajmabadi CyrusNajmabadi closed this as not planned Won't fix, can't repro, duplicate, stale Dec 20, 2024
@dotnet-policy-service dotnet-policy-service bot removed the untriaged Issues and PRs which have not yet been triaged by a lead label Dec 20, 2024
@CyrusNajmabadi
Copy link
Member

Closing as this is external. I can't move issues from dotnet to Microsoft, so you'll have to create a new issue there

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants