Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#WPF生成错误:CS0234命名空间中不存在类型或命名空间名称**_C#_Wpf_Xaml_Visual Studio 2017 - Fatal编程技术网

C#WPF生成错误:CS0234命名空间中不存在类型或命名空间名称**

C#WPF生成错误:CS0234命名空间中不存在类型或命名空间名称**,c#,wpf,xaml,visual-studio-2017,C#,Wpf,Xaml,Visual Studio 2017,几天来,我一直在研究这个错误,但我还没有找到解决办法 在我的项目“Arcanium”中,引发以下错误: 中不存在类型或命名空间名称“GameWindow” 命名空间“Arcanium.Arcanium.ClientSide”(是否缺少程序集 参考?) [编辑]在GameWindow.xaml的第8行抛出错误 以下是课程: GameWindow.xaml(Arcanium.Clientside): GameWindow.xaml.cs(Arcanium.ClientSide): 使用Arca

几天来,我一直在研究这个错误,但我还没有找到解决办法

在我的项目“Arcanium”中,引发以下错误:

中不存在类型或命名空间名称“GameWindow” 命名空间“Arcanium.Arcanium.ClientSide”(是否缺少程序集 参考?)

[编辑]在GameWindow.xaml的第8行抛出错误

以下是课程: GameWindow.xaml(Arcanium.Clientside):


GameWindow.xaml.cs(Arcanium.ClientSide):

使用Arcanium.ClientSide.Engine;
使用Arcanium.Engine.Graphics;
使用Arcanium.Engine.User;
使用制度;
使用System.Collections.Generic;
使用系统图;
使用System.Linq;
使用系统文本;
使用System.Threading.Tasks;
使用System.Windows;
使用System.Windows.Controls;
使用System.Windows.Data;
使用System.Windows.Documents;
使用System.Windows.Input;
使用System.Windows.Interop;
使用System.Windows.Media;
使用System.Windows.Media.Imaging;
使用System.Windows.Shapes;
名称空间Arcanium.ClientSide{
/// 
///GameWindow.xaml的交互逻辑
/// 
公共部分类GameWindow:窗口{
公共静态int-SizeX{get;private set;}
公共静态int-SizeY{get;private set;}
私有静态游戏窗口_窗口;
公共游戏窗口(){
初始化组件();
_窗口=这个;
}
公共静态无效绘图框(快速位图框){
_window.Background=新的ImageBrush(ImageSourceForBitmap(frame.GetBitmap());
frame.Dispose();
}
专用静态图像源ImageSourceForBitmap(位图bmp){
var handle=bmp.GetHbitmap();
试一试{
返回Imaging.CreateBitmapSourceFromHBitmap(handle、IntPtr.Zero、Int32Rect.Empty、BitmapSizeOptions.FromEmptyOptions());
}最后{NativeMethods.DeleteObject(handle);}
}
已激活私有void(对象发送方、事件参数){
SizeX=512;
SizeY=512;
Game.ActivateGameLoop();
}
私有void OnClosing(对象发送方,System.ComponentModel.CancelEventArgs e){
游戏。跑步=错误;
}
私有void OnKeyDown(对象发送方,KeyEventArgs e){
输入。手动键盘按键(e键);
}
私有void OnKeyUp(对象发送方,KeyEventArgs e){
输入。手柄键盘释放(e键);
}
私有void OnSizeChanged(对象发送方,SizeChangedEventArgs e){
抛出新的NotImplementedException();
}
}
}
(我想不出正确的格式,这是我第一次在这里问)

我已经试过几种方法了

  • 奇怪的是,编译器在名称空间“Arcanium.Arcanium.Clientslide”中搜索GameWindow,而我的类在“Arcanium.ClientSide”中。为了防止这种情况,我尝试从类路径(GameWindow.xaml,第1行)中删除Arcanium,这会导致它找不到事件的方法(在GameWindow.xaml中注册,第8行),并且不再知道InitializeComponent()方法,这导致我的结论GameWindow.xaml.cs无法正确继承

  • 我已尝试重新启动Visual Studio和我的整个计算机

  • 我试过清理和重建这个项目

  • 我尝试将目标平台从x64改为x32,然后再改回来(如中所建议)

  • [编辑]我已尝试删除窗口(两个类)并重新添加它们。我一注册事件,错误就回来了

  • 此错误仅在我尝试构建项目时发生。Visual Studio不会在文本编辑器中对其进行标记

    当我尝试按照Bijan的请求将Xaml中的x:Class路径更改为“GameWindow”时,它似乎找到了类,但没有找到其中的方法,并且它将InitializeComponent()标记为不存在


    有什么提示吗?

    如果从头开始重新创建一个新的XAML文件呢?很抱歉,我没有列出。已经试过几次了。一旦我添加回事件注册,错误就会再次出现。我会把它写进我的问题中,你的xaml和cs文件在一个空项目中运行良好。你需要寻找其他的东西。是否显示指向xaml文件的错误?是的,第8行,事件所在位置。Visual Studio的版本是什么?
    <Window x:Name="Arcanium" x:Class="Arcanium.ClientSide.GameWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:Arcanium.ClientSide"
        mc:Ignorable="d"
        Title="Arcanium" Height="512" Width="512" Activated="OnActivated" Closing="OnClosing" KeyDown="OnKeyDown" KeyUp="OnKeyUp" SizeChanged="OnSizeChanged">
    <Grid>
    
    </Grid>
    
    using Arcanium.ClientSide.Engine;
    using Arcanium.Engine.Graphics;
    using Arcanium.Engine.User;
    using System;
    using System.Collections.Generic;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Data;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Interop;
    using System.Windows.Media;
    using System.Windows.Media.Imaging;
    using System.Windows.Shapes;
    
    namespace Arcanium.ClientSide {
        /// <summary>
        /// Interaction logic for GameWindow.xaml
        /// </summary>
        public partial class GameWindow : Window {
    
    
    public static int SizeX { get; private set; }
    public static int SizeY { get; private set; }
    
    private static GameWindow _window;
    
    public GameWindow() {
        InitializeComponent();
        _window = this;
    }
    
    public static void DrawFrame(FastBitmap frame) {
        _window.Background = new ImageBrush(ImageSourceForBitmap(frame.GetBitmap()));
        frame.Dispose();
    }
    
    private static ImageSource ImageSourceForBitmap(Bitmap bmp) {
        var handle = bmp.GetHbitmap();
        try {
            return Imaging.CreateBitmapSourceFromHBitmap(handle, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
        } finally { NativeMethods.DeleteObject(handle); }
    }
    
    private void OnActivated(object sender, EventArgs e) {
        SizeX = 512;
        SizeY = 512;
    
        Game.ActivateGameLoop();
    }
    
    private void OnClosing(object sender, System.ComponentModel.CancelEventArgs e) {
        Game.Running = false;
    }
    
    private void OnKeyDown(object sender, KeyEventArgs e) {
        Input.HandleKeyboardPress(e.Key);
    }
    
    private void OnKeyUp(object sender, KeyEventArgs e) {
        Input.HandleKeyboardRelease(e.Key);
    }
    
    private void OnSizeChanged(object sender, SizeChangedEventArgs e) {
        throw new NotImplementedException();
    }
    
    
    }
    }