- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在 View 模型中订阅了一个事件。事件订阅是在通过 Unity 创建的 View 模型的构造函数中完成的。
我发现如果我订阅为:
showViewAEvent.Subscribe(ShowViewAHasBeenRequested) 或 showViewAEvent.Subscribe(ShowViewAHasBeenRequested, False) 我收到以下错误:
// {System.MethodAccessException: ModuleA.Views.ModuleAViewModel.ShowViewAHasBeenRequested(Boolean)
//at System.Delegate.BindToMethodInfo(Object target, RuntimeMethodHandle method, RuntimeTypeHandle methodType, DelegateBindingFlags flags)
//at System.Delegate.CreateDelegate(Type type, Object firstArgument, MethodInfo method, Boolean throwOnBindFailure)
//at System.Delegate.CreateDelegate(Type type, Object firstArgument, MethodInfo method)
//at Microsoft.Practices.Composite.Events.DelegateReference.TryGetDelegate()
//at Microsoft.Practices.Composite.Events.DelegateReference.get_Target()
//at Microsoft.Practices.Composite.Events.EventSubscription`1..ctor(IDelegateReference actionReference, IDelegateReference filterReference)
//at Microsoft.Practices.Composite.Presentation.Events.CompositePresentationEvent`1.Subscribe(Action`1 action, ThreadOption threadOption, Boolean keepSubscriberReferenceAlive, Predicate`1 filter)
//at Microsoft.Practices.Composite.Presentation.Events.CompositePresentationEvent`1.Subscribe(Action`1 action, ThreadOption threadOption, Boolean keepSubscriberReferenceAlive)
//at Microsoft.Practices.Composite.Presentation.Events.CompositePresentationEvent`1.Subscribe(Action`1 action, Boolean keepSubscriberReferenceAlive)
//at ModuleA.Views.ModuleAViewModel..ctor(IEventAggregator eventAggregator, IRegionManager regionManager)
//at BuildUp_ModuleA.Views.ModuleAViewModel(IBuilderContext )
//at Microsoft.Practices.ObjectBuilder2.DynamicMethodBuildPlan.BuildUp(IBuilderContext context)
//at Microsoft.Practices.ObjectBuilder2.BuildPlanStrategy.PreBuildUp(IBuilderContext context)
//at Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context)}
但是,如果我在事件订阅上将标志设置为 true,则不会收到错误。
由于我是 prism 的新手,我仍在尝试确定是否在正确的位置创建订阅。
京东。
最佳答案
这是一个已知问题,此处有完整记录:
http://compositewpf.codeplex.com/WorkItem/View.aspx?WorkItemId=4925
CompositePresentationEvent<>.Subscribe() 中的错误可防止弱事件引用标题为必填项
描述 描述为必填项概述:
此类的 Subscribe() 方法被记录为默认创建 WeakReferences,或者在包含该参数的重载中指定为 keepSubscriberReferenceAlive=false 时。
详细信息:
只有在提供过滤器委托(delegate)时才能正确观察到此行为。在所有其他情况下(以及 Subscribe() 方法的所有重载),都会创建强引用 - 无论记录的默认值如何,也无论为 keepSubscriberReferenceAlive 参数提供的任何值如何。
此错误的根源可以在该方法的以下重载中找到:
CompositePresentationEvent.Subscribe(操作操作,ThreadOption threadOption,bool keepSubscriberReferenceAlive,谓词过滤器)
在此方法中,检查“filter”参数。如果过滤器不为空,则处理会正确继续。但是,如果此参数为 null,则创建一个新的传递委托(delegate)(始终返回 true)并将其用于过滤器。该错误在于,从此传递委托(delegate)创建的 DelegateReference 对象将 keepReferenceAlive 参数硬编码为值“true”。该值不应被硬编码,而应传递传入参数 keepSubscriberReferenceAlive。
解决方法:
此问题有一个简单的解决方法。注册订阅时,您应该始终使用上述详细重载,并始终提供过滤器委托(delegate)。切勿为过滤器参数传递“null”。如果不应过滤订阅,则在需要弱事件引用时应使用传递过滤器委托(delegate)(典型场景):
EventAggregator.GetEvent().Subscribe(MyHandler, ThreadOption.PublisherThread, false, (dummy) => true);
以下缩写重载没有解决方法,并且在修补底层错误之前不应使用这些重载:
CompositePresentationEvent.Subscribe(操作操作)CompositePresentationEvent.Subscribe(Action 操作,ThreadOption threadOption)CompositePresentationEvent.Subscribe(Action 操作,bool keepSubscriberReferenceAlive)CompositePresentationEvent.Subscribe(Action action, ThreadOption threadOption, bool keepSubscriberReferenceAlive)
关于silverlight - 使用 Prism 进行事件订阅,给出方法访问异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1637720/
我想将使用 Prism 4 编写的项目迁移到 Prism 6。 在 Prism 4 中 CompositePresentationEvent类型位于Microsoft.Practices.Compos
Pattern of pub-sub events is that the publisher should not know or care if there are any subscribers
我刚刚使用 MVVMLight、PRISM 和 DryIoc 启动了我的第一个 WPF 应用程序。 App.xaml 引用 prism:PrismApplication,如 https://prism
Microsoft 的 Patterns and Practices 提供的示例非常有用: 大约六个更简单的快速入门 其中涉及具体问题 股票交易者引用实现 ,这是一个相当全面的应用程序 但它缺乏更有用
prism 中共享服务的目的和用途是什么? 哪些事情会让我认为我必须使用共享服务而不是 Event Aggregator? 最佳答案 从事件订阅者的角度来看 EventAggregator,它有利于获
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 想改进这个问题?将问题更新为 on-topic对于堆栈溢出。 3年前关闭。 Improve this qu
寻找一个简单的 helloWorld EventAggregator 示例。我试图理解这一点,并且在遵循 RI 示例时遇到了一些困难。 谢谢 N 最佳答案 Prism 4.0 包括 EventAggr
我只是想知道区域的意义是什么。我想我不明白他们解决的问题。 例如,我看到很多人使用区域作为导航区域,但是为什么不将 ItemsControl 绑定(bind)到 ObservableCollectio
最近想将我的 WPF Prism 应用程序迁移到 7.1,这样做时我遇到了有关 Unity.Abstractions 的丢失引用错误。 将 Prism nuget 软件包升级到 Prism7.1,如下
在我的根 View 模型中,我称之为 await _navigationService.NavigateAsync( "/NavigationPage/Page1of2", useMo
在 2.1.x 时间框架中讨论了与 Prism 的集成,我们是 @2.4.x,Prism 4 现已推出,/contrib 中的 RIStockTrader 示例只是一个默认的 XAML 项目。 它应该
我正在使用 Prism4,并且在我的一个模块中,我试图用一个区域注册一个 View ,并处理它的按钮单击事件(当用户单击 View 上的按钮时发布)。 public class MyModule :
几个月来,我一直在将 Prism 2.0 用于个人项目。我最近听说过 Caliburn,我想知道是否有令人信服的理由让我考虑这样做。 我喜欢 Prism 的动态模块加载能力。我打算为我的应用程序构建模
我正在尝试对我的 Windows 应用商店应用程序中的暂停事件使用react。我添加了适当的回调方法,但遇到了问题: App.Current.Suspending += Current_Suspend
我目前正在尝试完成 this tutorial让 Prism 与 Spring.net 一起工作。 通过 NuGet(或手动引用程序集)引用 Prism4 和 Spring.Net 后,设置 Boot
几个月来,我一直在使用带有以下 XAML 命名空间声明的 Prism 6: xmlns:prism="http://www.codeplex.com/prism" 但我注意到这个命名空间 URL(重定
我在 PRISM 中实现应用程序,它需要从 dll 文件中动态导入模块。我设法做到了 - 他们正在导入,但我无法显示它。我决定创建一个特殊的模块来封装它——让我们称之为 ModuleDock。所以我们
我要创建的是一个 Silverlight 应用程序,其中包含几个选项卡/模块,这些选项卡/模块都是单独的 DLL。 我看到 PRISM 具有似乎针对 UI 的 Shell/Module 概念,并且我找
请帮忙 - 我迷路了! 我正在编写一个具有一些控件和一些屏幕的小型桌面应用程序。这应该稍后与一个小型网站集成,也有一些屏幕。这个想法是让用户编辑视频并选择图像,然后与她的 friend 分享他们的结果
我在使用方法时遇到问题 this.regionManager.RegisterViewWithRegion("TextRegion", typeof(TextView)); 如果我以某种方法在 Boo
我是一名优秀的程序员,十分优秀!