我的项目找不到构造函数,即使我看到构造函数定义得很清楚
本文关键字:构造函数 定义 我看 清楚 项目 找不到 我的 | 更新日期: 2023-09-27 18:04:01
不管什么原因,下面代码的最后一行抱怨没有为包含两个参数的InputDialog找到构造函数。
using MahApps.Metro.Controls;
using MahApps.Metro.Controls.Dialogs;
namespace order
{
public static class DialogManager
{
public static Task<string> ShowInputAsync(this MetroWindow window, string title, string message, MetroDialogSettings settings = null)
{
window.Dispatcher.VerifyAccess();
return HandleOverlayOnShow(settings, window).ContinueWith(z =>
{
return (Task<string>)window.Dispatcher.Invoke(new Func<Task<string>>(() =>
{
if (settings == null)
settings = window.MetroDialogOptions;
//create the dialog control
InputDialog dialog = new InputDialog(window, settings); // error: does not contain a constructor With 2 arguments
我检查了InputDialog的代码,发现如下:
namespace MahApps.Metro.Controls.Dialogs
{
public partial class InputDialog : BaseMetroDialog
{
internal InputDialog(MetroWindow parentWindow)
: this(parentWindow, null)
{
}
internal InputDialog(MetroWindow parentWindow, MetroDialogSettings settings)
: base(parentWindow, settings)
{
InitializeComponent();
}
显然这个类有正确的名字,有正确的构造函数,有两个参数和正确的类型。那么是什么导致了误差呢?
我基本上是试图改造这里发现的代码有一个身份验证对话框,要求4-6位pin与密码框。因为我不应该改变MaHapps Metro代码,我复制并试图修改代码以适应我的需要。
类InputDialog
的构造函数的访问修饰符必须是public
,不能是internal
:
内部"的实际应用c#关键字
修饰符internal
意味着它只能在同一程序集中的文件中访问
修饰符public
意味着它可以被任何其他可以引用InputDialog
的类访问