Ich entwickle eine einfache .NET 8 WPF -Anwendung mit Visual Studio -Code unter Windows mit der C# Dev -Kit -Erweiterung. Im aktuellen Kontext ") in meinem Mainwindow.xaml.cs < /code> Datei für: < /p>
[*]
Code: Select all
InitializeComponent()
Dies bedeutet IntelliSense, Code -Navigation und möglicherweise andere Erweiterungen, die auf genaue Codeanalyse (wie die Berichterstattung bis zugleisen) beruhen. />
- OS: Windows 10 < /li>
IDE: VS-Code < /li>
Erweiterung: C# Dev Kit < /li>
Projektziel-Framework: Net8.0-Windows < /code> < />
sdk installiert: .Net 8 --version )
Voller Code hier
Code: Select all
SimpleWpfApp/SimpleWpfApp.csproj
Code: Select all
WinExe
net8.0-windows
enable
enable
true
< /code>
[b]SimpleWpfApp/MainWindow.xaml
Code: Select all
< /code>
[b]SimpleWpfApp/MainWindow.xaml.cs
Code: Select all
using System.Windows;
namespace SimpleWpfApp
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent(); // CS0103 Error here in VS Code
}
private void GreetButton_Click(object sender, RoutedEventArgs e)
{
// CS0103 Error on NameTextBox in VS Code
string name = NameTextBox.Text.Trim();
if (!string.IsNullOrEmpty(name))
{
// CS0103 Error on GreetingTextBlock in VS Code
GreetingTextBlock.Text = $"Hello, {name}!";
}
else
{
// CS0103 Error on GreetingTextBlock in VS Code
GreetingTextBlock.Text = "Please enter your name.";
}
}
// Helper methods used for testing
public string GetGreetingText()
{
// CS0103 Error on GreetingTextBlock in VS Code
return GreetingTextBlock.Text;
}
public void SetNameAndGreet(string name)
{
// CS0103 Error on NameTextBox & GreetButton in VS Code
NameTextBox.Text = name;
GreetButton_Click(GreetButton, new RoutedEventArgs());
}
}
}
< /code>
[b]Troubleshooting Steps Taken:[/b]
[*][b]Reload Window/Restart VS Code:[/b] Done multiple times.
[*][b]Clean Build:[/b] Deleted bin
Code: Select all
obj
Code: Select all
dotnet build
Code: Select all
Using local .NET runtime at "c:\Users\tiny10\AppData\Roaming\Code\User\globalStorage\ms-dotnettools.vscode-dotnet-runtime\.dotnet\9.0.4~x64~aspnetcore\dotnet.exe"
Found installed dotnet location "C:\Program Files\dotnet\dotnet.exe" to load projects.
< /ol>
Code: Select all
.vscode/settings.json
Code: Select all
{
"dotnet.dotnetPath": "C:\\Program Files\\dotnet",
"dotnet.server.useOmnisharp": false, // Dev Kit recommends disabling OmniSharp
"editor.formatOnSave": true,
"[csharp]": {
"editor.defaultFormatter": "ms-dotnettools.csharp",
"editor.formatOnSave": true
},
"dotnet-test-explorer.testProjectPath": "**/*Tests.csproj",
"coverage-gutters.coverageFileNames": [
"lcov.info"
],
"files.exclude": {
"**/bin": true,
"**/obj": true,
"**/.vs": true,
"**/TestResults": true
},
"task.autoDetect": "off",
"terminal.integrated.env.windows": {
"DOTNET_ROOT": "C:\\Program Files\\dotnet"
},
"terminal.integrated.defaultProfile.windows": "Command Prompt"
}
< /code>
[b]Question:[/b]
How can I configure VS Code / C# Dev Kit to correctly recognize the WPF-generated members (InitializeComponent