【发布时间】:2012-12-14 20:10:19
【问题描述】:
正在使用 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 不包含"method and 没有扩展方法“方法”接受类型的第一个参数 可以找到 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>
【问题讨论】:
-
我没有看到您的 className 定义中定义了任何方法()。检查您尝试调用的方法是否存在。
-
'三维布尔数组' - 我的头疼 ;-)
-
@ScottChapman 抱歉,是的,我已经定义了一个方法,但是我把它省略了,因为类本身真的很长而且很复杂,但我不认为问题出在 C# 上,是那么可能是这种情况?
-
似乎很清楚...从您发布的代码中,类 Solver 有一个无参数的构造函数,但是在 Button_Click_1 中,您正在使用期望和参数(内容)的构造函数来新建一个实例
-
但是 Solver 类确实有一个参数。
标签: c# xaml windows-8 assembly-references