IronRuby和处理XAML UI事件 [英] IronRuby and Handling XAML UI Events

查看:122
本文介绍了IronRuby和处理XAML UI事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是通过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!)
结束
 

包括其他的选择。

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.

这篇关于IronRuby和处理XAML UI事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆