c# - 错误:在类型中找不到正确签名的 EventHandler“btnLogin_Clicked”
问题描述
我正在尝试在 Xamarin 中创建针对 LDAP 的身份验证。我有 Main.xaml,在其中创建了简单的登录表单 (Entry Placeholder="*Password" IsPassword="True" x:Name="login_password") 按钮 (Button Clicked ="btnLogin_Clicked" Text="Sign in" x:Name ="btnLogin")。Main.xaml.cs 包含 LDAP 连接的代码。我在那里检查凭据并尝试绑定。
不幸的是,我收到此错误:“EventHandler 'btnLogin_Clicked' 在类型 'Main.xaml' 中找不到正确的签名”。
我花了很多时间在这上面,但仍然无法弄清楚我做错了什么。如果有人能帮我解决这个问题,或者给我一些关于我可以在哪里搜索答案的建议,我将不胜感激。
我的一段代码:
public void btnLogin_Clicked(object sender,string login_username, string login_password, System.EventArgs e)
{
string searchBase = "dc = it, dc = local";
string searchFilter = "(amemberOf=ALL)";
string ldapHost = "7777.. ";
int ldapPort = 389;
string loginDN = "dc = it, dc = local";
/*if username or passworwd fields are empty show an error*/
if (login_username is null || login_password is null)
{
DisplayAlert("Alert", "Please, enter your credentials", "OK");
}
else
{
/*creating an LDAP instance*/
using (LdapConnection connection = new LdapConnection())
/*here we create new ldap connection*/
try
{
/*connect function will creat socket connection to the server*/
connection.Connect(ldapHost, ldapPort);
connection.Bind(string.Format("{0}@{1}", loginDN, login_username), login_password);
LdapSearchQueue queue = connection.Search(searchBase,
LdapConnection.SCOPE_ONE, searchFilter, null, false, (LdapSearchQueue)
null, (LdapSearchConstraints)null);
LdapMessage message;
while ((message = queue.getResponse()) != null)
{
if (message is LdapSearchResult)
{
/*display message if connect*/
DisplayAlert("" ," logged in ", "OK ");
}
else
{
/*if the message is not null but the login was failed*/
DisplayAlert("", "Login failed", "OK ");
}...
解决方案
Button 的事件处理程序具有签名
public void btnLogin_Clicked(object sender, System.EventArgs e)
你不能只在签名中添加额外的参数
推荐阅读
- java - android java中的内部类泄漏内存?
- python - 我在 Python Hackerrank 上收到错误“Sdout 没有响应”
- curl - 为什么多格式的 curl 命令不起作用
- java - 使用 Java 中的 ARN 角色连接到 AWS S3
- javascript - 如何使用 Chrome 驱动程序(Python 和 Selenium)在 chrome 中禁用 JavaScript
- android - Android 在 CheckedTextView 中更改颜色
- angular - 跟踪网站上的设计更改
- asp.net - 通过 MailKit 发送电子邮件的问题
- ios - +[_CFXNotificationTokenRegistration keyCallbacks] 崩溃
- reactjs - 当我们使用 react-datepicker 时,时间正在改变