如何在通用EventHandler <t>中使用Rx Observable?

时间:2015-10-09 14:20:53

标签: c# system.reactive

以下代码可以使用

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class='questionBlock'>
  <div class='questionBlockTitle '><span class='sectionQuestionBlockNumber'>4. </span><span class='sectionQuestionBlockTitle'>What can they do less of?</span>

    <div class='msgErrorRequired'></div>
    <div class='expandArrow downArrow'></div>
  </div>
  <div class='questionBlockExpand formQuestionPadding'>
    <div class='sectionQuestionBlockHelpText'></div>
    <input type='hidden' value='' name='13' mandatory='True' id='13' error=''>
    <div style='width:700px;height:100px;' class='sectionItemBlock '> <span class='questionControl'>
                <textarea  id='qt_13' name='qt_13' class="noEmpty" style='width:695px;height:100px;' maxlength='100' question='13' disabled='disabled' ></textarea>
            </span>

    </div>
  </div>
</div>

但是如何使Observable.FromEventPattern采用EventHandler&lt; T&gt; ?像

这样的东西
var mouseTracker = Observable.FromEventPattern<MouseEventArgs>(form1, "MouseMove");
//for Form1_MouseMove(object sender, MouseEventArgs e)

修改

格鲁克的答案有效。我需要将FromEventPattern更改为FromEvent。

var mouseTracker = Observable.FromEventPattern<EventHandler<StockQuote>>(_board, "QuoteUpdated");
//for board_QuoteUpdated(object sender, StockQuote stockQuote)

1 个答案:

答案 0 :(得分:2)

没有通用类型EventArgs<T>

假设你需要的是为一个不遵循标准事件模式的事件创建一个observable(在你的情况下,它意味着StockQuote类型不会延伸{ {1}}),然后EventArgs无法使用。

但您仍然可以使用FromEventPattern

FromEvent