![](/img/trans.png)
[英]Does not contain a constructor that takes 1 argument even though there is a constructor that takes 1 argument
[英]Button does not contain a constructor that takes 0 argument
我目前正在VS2017上的Xamarin PCL項目上工作。 在Android項目下,我創建了一個名為TestBtn的類。 代碼如下所示。 我遵循了按鈕元數據,並相應地聲明了構造函數,如下所示。 但是我收到一個錯誤,Button不包含采用0參數的構造函數。
知道為什么我會收到此錯誤嗎?
namespace CustomRibbonRenderer.Droid
{
public class TestBtn: Button
{
public TestBtn(Context context)
{
}
}
}
Button
代表一個按鈕小部件。 用戶可以按下或單擊按鈕以執行操作。 根據Xamarin文檔, Button
類接受4個公共構造函數和一個受保護的構造函數:
Button(Context)
Button(Context, IAttributeSet)
Button(Context, IAttributeSet, Int32)
Button(Context, IAttributeSet, Int32, Int32)
您未調用base()
代碼中出現錯誤。 base
關鍵字在構造函數中使用。 需要派生類構造函數從其基類調用構造函數。
您有一個采用一個參數(上下文)的構造函數。 如果不帶參數初始化TestBtn,則可能會出現錯誤。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.