'正在用 C# 和 XAML 为 Windows 8 制作应用程序。
我在名为 AppNamespace 的命名空间中定义了两个类,其中一个类在其构造函数中采用一个 3 维布尔数组:
public class Solver
{
// Board is a class also in this namespace but I don't think the issue is
//there, so I've omitted it's definition
private Board current;
// You can see that the class clearly DOES take a parameter of the same type
// as the array "content" (which is defined later)
public Solver (bool[, ,] initial)
{
// The parameter is then used to construct a "Board" class within the
// "Solver" class.
current = new Board(initial);
}
// Several methods within the class
}
所以定义见上。
然后,我在名为“NewPage.xaml”的 gridapp 上创建了一个新页面,在该页面中有一些文本框可以操作数组中的值。(这里似乎没有问题)
然后在'NewPage.xaml.cs'按钮被点击的时候,应该在类上创建一个实例,然后在类内运行一个方法,在顶部的“NewPage.xaml.cs”我定义了一个三维数组如下所示,
// Declare the namespace where the class "Solver" is situated
using App.Classes;
namespace App
{
// So below is the C# part of the page "PuzzleSolver"
public sealed partial class PuzzleSolver : App.Common.LayoutAwarePage
{
// Create an array called content
bool[, ,] content = new bool[9, 9, 9];
public PuzzleSolver()
{
this.InitializeComponent();
//Set every cell of the created content array to true
for (int i = 0; i <= 8; i++)
{
for (int j = 0; j <= 8; j++)
{
for (int k = 0; k <= 8; k++)
{
content[i, j, k] = true;
}
}
}
}
/* There are some methods which change information in the array "Content" based on the
stuff input into the XAML textboxes on the page. */
// The below method is invoked when a XAML Button is clicked on the page
// and I intend it to create a "Solver" object, using the "content" array
// from this page as a parameter
private void Button_Click_1(object sender, RoutedEventArgs e)
{
// So now I create the and pass in the "content" array
Solver newSolve = new Solver(content);
newSolve.Solve();
}
}
问题是,编译器承认“className”是一个类,但说它没有一个带 1 个参数的构造函数,它还说:
“ProjectName.className 不包含“方法”的定义,并且没有扩展方法“方法”接受 ProjectName.className 类型的第一个参数(您是否缺少 using 指令或程序集引用)
谁能从这些信息中确定我的问题出在哪里?
我对此进行了编辑以显示其他命名空间声明,首先是“Solver.xaml.cs”上的声明:
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using App.Classes;
现在关于“Solver.xaml”的声明:
<common:LayoutAwarePage
x:Name="pageRoot"
x:Class="App.Solver"
DataContext="{Binding DefaultViewModel, RelativeSource={RelativeSource Self}}"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:App"
xmlns:common="using:App.Common"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Page.Resources>
<x:String x:Key="PageName">Solver</x:String>
</Page.Resources>