Morbid
Morbid

Reputation: 31

Constructor on type xxx not found

class ItemBaseModel : TextBox
{
    public string item_name { get; set; }

    public ItemBaseModel(string item_name)
    {           
        this.item_name = item_name;
        this.ReadOnly = true;
        this.Multiline = true;
        this.TextAlign = HorizontalAlignment.Center;
    }
}

So this is my base class, which derives from TextBox control.

class ItemWeaponModel : ItemBaseModel
{
    int min_dmg { get; set; }
    int max_dmg { get; set; }
}

public ItemWeaponModel(string item_name, int min_dmg, int max_dmg) : base(item_name)
    {
        this.min_dmg = min_dmg;
        this.max_dmg = max_dmg;
    }

And this is my class, which derives from the first class.

Now, the problem is that when I open my ItemWeaponModel.cs file in my solution explorer, I am getting the following error:

Constructor error

Althought I can run my project without any issues. What is happening? Thanks for response.

Upvotes: 0

Views: 662

Answers (1)

sanitizedUser
sanitizedUser

Reputation: 2115

The problem is that the designer expects that your class has a parameterless constructor. It cannot call any other.

Try to provide a simple parameterless constructor just for the designer. You don't have to use it in your actual application code.

class ItemBaseModel : TextBox
{
    public string item_name { get; set; }

    public ItemBaseModel(string item_name)
    {           
        this.item_name = item_name;
        this.ReadOnly = true;
        this.Multiline = true;
        this.TextAlign = HorizontalAlignment.Center;
    }
    public ItemBaseModel() : this("default")
    {}
}

Upvotes: 1

Related Questions