CommunityToolkit / CommunityToolkit/dotnet

.net 4.7.2 Accessing properties causing compilation error

Aperta
#643 16 commenti 0 reazioni 0 assegnatari Vedi su GitHub
bug :bug: mvvm-toolkit :toolbox: needs author feedback :memo:
Lingua principale
C#
Stelle
3.8k
Fork
400
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

### 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.

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Riproduci l’esempio in Windows/Main/MainViewModel.cs nel progetto .NET 4.7.2 e verifica come si comporta la generazione di ObservableProperty e RelayCommand quando viene fatto riferimento alla proprietà Title. Confronta i membri generati con la configurazione del progetto e con l’impostazione menzionata IncludePackageReferencesDuringMarkupCompilation. Il lavoro è completato quando l’esempio viene compilato e il binding XAML esistente continua a funzionare.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
csharp
Ambito
desktop
Tipo di issue
Bug
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.