我尝试开始使用 .Net MAUI,并按照以下描述的步骤设置了我的开发环境:
我还运行了“maui-check”CLI 工具,一切都已检查完毕,但是当我使用 Visual Studio 2019 v16.11.0 Preview 2.0(在 Windows 10 Home 20H2 上运行)创建新的 .NET MAUI 应用程序时,我得到了“当前上下文中不存在名称“InitializeComponent”构建错误。它还找不到对表单上任何控件的引用,例如“当前上下文中不存在名称“CounterLabel””
我已经尝试了这篇文章中的几乎所有内容。名称“InitializeComponent”在当前上下文中不存在,其中包含添加和删除文件、进行更改以及将其改回等建议......基本上除了在许愿井中扔一分钱之外的所有内容。
我发现一个常见的错误是命名空间不匹配,但以下是我所显示的命名空间是正确的:
应用程序.xaml:
<Application xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:MauiApp1"
x:Class="MauiApp1.App">
...
</Application>
Run Code Online (Sandbox Code Playgroud)
应用程序.xaml.cs
using Microsoft.Maui;
using Microsoft.Maui.Controls;
using Microsoft.Maui.Controls.PlatformConfiguration.WindowsSpecific;
using System;
using Application = Microsoft.Maui.Controls.Application;
namespace MauiApp1
{
public partial class App : Application
{
public App()
{
InitializeComponent(); <-- This is throwing the build error...
}
protected override IWindow CreateWindow(IActivationState activationState)
{
this.On<Microsoft.Maui.Controls.PlatformConfiguration.Windows>()
.SetImageDirectory("Assets");
return new Microsoft.Maui.Controls.Window(new …Run Code Online (Sandbox Code Playgroud) 我在使用Visual Studio 2010和C++时遇到了一些奇怪的行为.我有一个头文件,我在其中声明了一些全局常量
#ifndef CONSTANTS_H
#define CONSTANTS_H
#define WIN32_LEAN_AND_MEAN
// Macros...
#define SAFE_RELEASE(ptr) { if (ptr) { ptr->Release(); ptr = NULL } }
#define SAFE_DELETE(ptr) { if (ptr) { delete ptr; ptr = NULL; } }
// Constants...
const char* CLASS_NAME = "WinMain";
const char GAME_TITLE[] = "DirectX Window";
const int GAME_WIDTH = 640;
const int GAME_HEIGHT = 480;
#endif
Run Code Online (Sandbox Code Playgroud)
我的问题来自以下行:
const char* CLASS_NAME = "WinMain";
Run Code Online (Sandbox Code Playgroud)
当它是这样的,我构建我的解决方案时,我得到以下2个错误:
error LNK1169: one or more multiply defined symbols found,和
error LNK2005: "char …