Hello got the following wpf code thats using source generators utlizing mvvm community toolkit version 8:
public partial class CalculatorVM : ObservableObject
{
[ObservableProperty]
private int buttonOne = 1;
[ObservableProperty]
private int buttonTwo = 2;
[ObservableProperty]
private int buttonThree = 3;
[ObservableProperty]
private int buttonFour = 4;
[ObservableProperty]
private int buttonFive = 5;
[ObservableProperty]
private int buttonSix = 6;
[ObservableProperty]
private int buttonSeven = 7;
[ObservableProperty]
private int buttonEight = 8;
[ObservableProperty]
private int buttonNine = 9;
[ObservableProperty]
private double result, lastNumber;
[ObservableProperty]
SelectedOperator selectedOperator;
[ObservableProperty]
private int clickedNumber;
[ObservableProperty]
private Label resultLabel;
[RelayCommand]
public void NumbercClicked(int number)
{
var selectedNumber = number switch
{
1 => ButtonOne,
2 => ButtonTwo,
3 => ButtonThree,
4 => ButtonFour,
5 => ButtonFive,
6 => ButtonSix,
7 => ButtonSeven,
8 => ButtonEight,
9 => ButtonNine,
};
ClickedNumber = selectedNumber;
if (ClickedNumber == 0) Result = 0;
else Result = Result + selectedNumber;
}
I cant compile, tells me buttonOne etc dont exsist in the current context, The Repo: https://github.com/KostaKing/Calculator/tree/master/Calculator/ViewModels Anybody has any idea?
You have old format csproj.
These explicitly list the files which are part of a project:
When the code generator creates a new file in a new format project, that is automatically going to be included in the project. New style projects include everything in their folders.
Old style ones only include what's listed in ItemGroup.
If your partial classes are being created then this is why they will be ignored.
You will need to upgrade the csproj to a new format.
The simplest way to do that is often to create a new solution and projects, copy in source files out your old solution.
You can target .net 4.8 if you really want to with a new format csproj. To do so be careful about which wpf project template you choose. There are two in vs2022.