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名称“;interactiveGrid“;在当前上下文中不存在_C#_Wpf - Fatal编程技术网

C# Wpf名称“;interactiveGrid“;在当前上下文中不存在

C# Wpf名称“;interactiveGrid“;在当前上下文中不存在,c#,wpf,C#,Wpf,我对wpf有一些问题。 我班上有一个学生 using System; using System.Collections.Generic; using System.Windows.Controls; namespace RatesScenarios.Controls { class InteractiveGrid : Grid, IDisposable { //... } } 当我将其添加到xaml时: <Window x:Class="RatesSce

我对wpf有一些问题。 我班上有一个学生

using System;
using System.Collections.Generic;
using System.Windows.Controls;

namespace RatesScenarios.Controls
{
    class InteractiveGrid : Grid, IDisposable
    {
    //...
    }
}
当我将其添加到xaml时:

<Window x:Class="RatesScenarios.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:controls="clr-namespace:RatesScenarios.Controls"
        Title="RatesScenarios" MinHeight="400" Width="700" Background="SteelBlue" SizeToContent="Manual">

为什么会发生这种情况?

这可能是一个愚蠢的问题,但您是否为InteractiveGrid声明了公共构造函数?
是否在MainWindow构造函数中调用InitializeComponent()方法?

存在现有代码,未生成

using System;
using System.Collections.Generic;
using System.Windows.Controls;

namespace RatesScenarios.Controls
{
    public class InteractiveGrid : Grid, IDisposable
    {
    #region IDisposable Members
        public void Dispose()
        {

        }
    #endregion

        private DataCell selectedCell;

        public DataCell SelectedCell
        {
            get { return selectedCell; }
        }

        public InteractiveGrid()
        {

        }

        public void Build(List<string> columnsHeaders, List<string> rowsHeaders, List<DataCell> dataCells)
        {

        }

        public void SelectCell(DataCell dataCell)
        {
            selectedCell = dataCell;
        }
    }
}

如果其他人在没有任何指示的情况下收到此错误,则关闭和打开.XAML文件会提示以下情况:

Error 2 Because 'MS.Internal.Design.Metadata.ReflectionTypeNode' is   
implemented in the same assembly, you must set the x:Name   
attribute rather than the  
MS.Internal.Design.Metadata.ReflectionPropertyNode attribute.
关于SO也有类似的问题:

您是否尝试过在控件的定义中添加public?公共类交互整体,“公共类交互整体”也不起作用。定义“class InteractiveGrid”必须起作用,因为它在单个程序集中声明。您是否尝试过x:Name=“InteractiveGrid”而不是Name=“InteractiveGrid”?是,“x:Name”解决了我的问题。谢谢你,劳兰。这是你的解决方案吗?如果是这样,请添加一些关于您为解决问题而采取的步骤的备注。如果没有,您应该在下次编辑您的问题。
using System;
using System.Collections.Generic;
using System.Windows.Controls;

namespace RatesScenarios.Controls
{
    public class InteractiveGrid : Grid, IDisposable
    {
    #region IDisposable Members
        public void Dispose()
        {

        }
    #endregion

        private DataCell selectedCell;

        public DataCell SelectedCell
        {
            get { return selectedCell; }
        }

        public InteractiveGrid()
        {

        }

        public void Build(List<string> columnsHeaders, List<string> rowsHeaders, List<DataCell> dataCells)
        {

        }

        public void SelectCell(DataCell dataCell)
        {
            selectedCell = dataCell;
        }
    }
}
public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();
    }
//..
}
Error 2 Because 'MS.Internal.Design.Metadata.ReflectionTypeNode' is   
implemented in the same assembly, you must set the x:Name   
attribute rather than the  
MS.Internal.Design.Metadata.ReflectionPropertyNode attribute.