【问题标题】:My project cannot find the constructor, even though I see it clearly defined?我的项目找不到构造函数,即使我看到它已明确定义?
【发布时间】:2014-07-06 20:04:56
【问题描述】:

无论出于何种原因,下面代码中的最后一行抱怨找不到包含 2 个参数的 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();
        }

很明显,该类具有正确的名称,以及带有 2 个参数和正确类型的正确构造函数。那么是什么导致了错误呢?

我实际上是在尝试改进找到here 的代码,使其具有一个要求输入带有密码框的 4-6 位密码的身份验证对话框。由于我不应该更改 MaHapps Metro 代码,因此我复制并尝试修改代码以满足我的需要。

【问题讨论】:

    标签: c# wpf mahapps.metro


    【解决方案1】:

    InputDialog的构造函数的访问修饰符必须是public,而不是internal

    http://msdn.microsoft.com/en-us/library/7c5ka91b.aspx

    Practical uses for the "internal" keyword in C#

    修饰符internal 表示只能在同一程序集中的文件中访问

    修饰符public表示它可以被任何其他可以引用InputDialog的类访问

    【讨论】:

    • 糟糕,我没有看到那个内部修饰符。所以我是SOL!
    • internal 不是这个意思。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-07-25
    • 2012-05-16
    • 2021-07-28
    • 2012-01-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多