CommunityToolkit / CommunityToolkit/dotnet
.net 4.7.2 Accessing properties causing compilation error
- Vorherrschende Sprache
- C#
- Sterne
- 3.8k
- Forks
- 400
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Beschreibung
### 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.
Beitragsleitfaden
Rechercherichtung
Reproduziere das Beispiel in Windows/Main/MainViewModel.cs im .NET 4.7.2-Projekt und untersuche, wie sich die Generierung von ObservableProperty und RelayCommand verhält, wenn auf die Title-Eigenschaft verwiesen wird. Vergleiche die generierten Member mit der Projektkonfiguration und der erwähnten Einstellung IncludePackageReferencesDuringMarkupCompilation. Als erledigt gilt die Aufgabe, wenn das Beispiel kompiliert und die bestehende XAML-Bindung weiterhin funktioniert.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- csharp
- Bereich
- desktop
- Issue-Typ
- Bug
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100