IronRuby和处理XAML UI事件事件、IronRuby、XAML、UI

2023-09-06 07:44:45 作者:弦断丶何人听

什么是通过IronRuby的脚本添加事件处理在XAML UI元素的最简明扼要的方式?假设:在code添加事件处理程序将被写入IronRuby的脚本和code来处理该事件将是在同一个IronRuby的脚本

我想下面的code,但在IronRuby的等效。操作简单Button1的Click事件。

 公共部分类窗口1:窗口
{
    公共窗口1()
    {
        的InitializeComponent();
        button1.Click + =新RoutedEventHandler(的button1_Click);
    }

    无效的button1_Click(对象发件人,RoutedEventArgs E)
    {
        的MessageBox.show(的Hello World!);
    }
}
 

解决方案

据我所知,.NET事件暴露由于参加的IronRuby块的方法。所以,你可以这样写:

  button1.click办|发件人,ARGS |
    的MessageBox.show(的Hello World!)
结束
 

这包括其他的选择。

Unity2019新手教程6.2.7 Unity UI事件响应

What it is the most brief and concise way of adding event handlers to UI elements in XAML via an IronRuby script? Assumption: the code to add the event handler would be written in the IronRuby script and the code to handle the event would be in the same IronRuby script.

I'd like the equivalent of the following code but in IronRuby. Handling a simple button1 click event.

public partial class Window1 : Window
{
    public Window1()
    {
        InitializeComponent();
        button1.Click += new RoutedEventHandler(button1_Click);
    }

    void button1_Click(object sender, RoutedEventArgs e)
    {
        MessageBox.Show("Hello World!");
    }
}

解决方案

So far as I know, .NET events are exposed as methods taking blocks in IronRuby. So, you can write:

button1.click do |sender, args|
    MessageBox.show("Hello World!")
end

This covers other options.