CommunityToolkit / CommunityToolkit/dotnet
.net 4.7.2 Accessing properties causing compilation error
- Dominant language
- C#
- Stars
- 3.8k
- Forks
- 400
- PR merge metrics
- No merged PRs in 30d
Description
### Describe the bug
```cs
public partial class MainViewModel : ObservableObject
{
[ObservableProperty]
public string _title = "Window Name";
[ObservableProperty]
public string _buttonCaption = "This is a button";
[RelayCommand(CanExecute = nameof(CanRunTestButton))]
public void RunTestButton()
{
Title = "The window name has changed";
}
public bool CanRunTestButton()
{
return Title == "Window Name";
}
}
```
When running this example, I am getting a compile error stating
> Rebuild started...
> 1>------ Rebuild All started: Project: LearningFramework, Configuration: Debug Any CPU ------
> Restored C:\Users\iifuz\source\repos\LearningFramework\LearningFramework\LearningFramework.csproj (in 10 ms).
> 1>C:\Users\iifuz\source\repos\LearningFramework\LearningFramework\Windows\Main\MainViewModel.cs(26,13,26,18): error CS0103: The name 'Title' does not exist in the current context
> 1>C:\Users\iifuz\source\repos\LearningFramework\LearningFramework\Windows\Main\MainViewModel.cs(31,20,31,25): error CS0103: The name 'Title' does not exist in the current context
> ========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========
> ========== Rebuild started at 7:58 AM and took 00.578 seconds ==========
Without accessing the Title property, data binding is working fine in the XAML.
I did see a separate closed issue on this github regarding a IncludePackageReferencesDuringMarkupCompilation property to set within the csproj, however this is not available in 4.7.2 from what I can tell?
### Steps to reproduce
Compile the code in the description.
### Expected behavior
That the code compiles and binds accordingly.
### Visual Studio Version
2022
### Help us help you
Yes, I'd like to be assigned to work on this item.
Contributor guide
Assessment
This issue has not been assessed yet.