c# - 在 Xamarin.Forms 中以编程方式引发控件事件

标签 c# xaml events xamarin xamarin.forms

我在 XAML 中定义了一个按钮:

<Button x:Name="loginButton" Text="Login" Clicked="OnLoginButtonClicked" />

是否有可能提高Clicked以编程方式事件?当然我可以打电话OnLoginButtonClicked ,但我很感兴趣 Clicked事件本身可以引发。

最佳答案

如果你只想调用 Clicked 操作,你可以这样做:

    var b = new Button();

    b.Clicked += (x, y) =>
    {
        //Your method here
    };

    var t = b as IButtonController;

    t.SendClicked(); //This will call the action

重要的是要注意这不是正确的。
正如之前提到的,调用实际方法是首选。

关于c# - 在 Xamarin.Forms 中以编程方式引发控件事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40842891/

相关文章:

c# - 如何在最新的 Chrome 版本中使用 C#、Selenium 处理 Windows 身份验证?

xaml - Xamarin Forms:如何为按钮添加填充?

javascript - 扩展类的 typescript 事件

c# - 从 .NET 附加到 COM 服务器中的事件时出现 E_ACCESSDENIED 异常

javascript - 在父级上鼠标悬停后防止子级单击?

c# - VC# 多鼠标

c# - IValueConverter 和可见性

c# - 使用Regex匹配SQL连接字符串的部分

c# - 如何复制现有列并将其插入到datagrid中?

wpf - 如何将索引属性绑定(bind)到 WPF 中的控件