大家好,我对 Rx 非常非常非常陌生,并试图组合一个简单的测试应用程序。它基本上使用 Rx 订阅窗口单击事件,并将文本框上的文本设置为“已单击”。这是一个 wpf 应用程序。这是xml:
<Window x:Class="Reactive.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Canvas>
<TextBlock Name="txtClicked" Text="Rx Test"/>
</Canvas>
</Grid>
这是背后的代码:
using System;
using System.Linq;
using System.Windows;
using System.Windows.Input;
namespace Reactive
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
/// <summary>
/// Initializes a new instance of the <see cref="MainWindow"/> class.
/// </summary>
public MainWindow()
{
InitializeComponent();
var xs = from evt in Observable.FromEvent<MouseEventArgs>(this, "MouseDown")
select evt;
xs.ObserveOnDispatcher().Subscribe(value => txtClicked.Text = "Clicked");
}
}
}
但由于某种原因,代码没有运行。我得到消息:
对匹配指定绑定约束的“Reactive.MainWindow”类型的构造函数的调用引发了异常。行号'3'和行位置'9
内部异常消息:
事件委托的形式必须为 void Handler(object, T) 其中 T : EventArgs。
请帮忙!!!