【问题标题】:How to raise Onload/OnUnload event from FrameworkElement for unit testing purposes?如何从 FrameworkElement 引发 Onload/OnUnload 事件以进行单元测试?
【发布时间】:2010-09-01 13:25:27
【问题描述】:

正如您所看到的here,我不能使用反射来获取这些FrameworkElement 事件背后的私有字段的多播委托,因为它们不是类似字段的。那么该怎么做呢?

【问题讨论】:

  • 在您最初的问题中,如果您可以获取 FrameworkElement.Loaded 和 FrameworkElement.Unloaded 的路由事件,那还不够吗?

标签: wpf unit-testing events reflection delegates


【解决方案1】:

请试试这个:

yourControl.RaiseEvent(new RoutedEventArgs(FrameworkElement.LoadedEvent));

它应该工作! :)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-10-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-10
    • 2012-04-12
    相关资源
    最近更新 更多