OpenNetCF.IOC 事件订阅未触发
我正在使用 OpenNetCF IOC 框架开发 Vb.net .Net 3.5 PDA 应用程序。我已经设置了事件来处理通过智能部分的导航,但是当我引发事件时,EventSubscription 不会触发。
我确信我错过了一些简单的事情,但我会很感激这样的建议。
Imports OpenNETCF
Imports OpenNETCF.IoC
Imports OpenNETCF.IoC.UI
Public Class MainContainer
<EventPublication(EventNames.Navigate)> _
Public Event NavigateToSmartPart As EventHandler(Of GenericEventArgs(Of SmartPart))
Public Sub New()
' This call is required by the Windows Form Designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
RootWorkItem.Items.Add(workspace, WorkspaceNames.StackWorkspace)
RootWorkItem.Services.AddOnDemand(Of XMLWrapper)()
RootWorkItem.Services.AddOnDemand(Of DataInterface)()
'RootWorkItem.SmartParts.AddNewDisposable(Of ViewCamera)()
RootWorkItem.SmartParts.AddNew(Of ViewGoodInInspection)()
RootWorkItem.SmartParts.AddNew(Of ViewLogon)()
RootWorkItem.SmartParts.AddNew(Of ViewPartCentre)()
RootWorkItem.SmartParts.AddNew(Of ViewSplash)()
End Sub
Private Sub MainContainer_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
RootWorkItem.Services.Get(Of DataInterface)().InitialseApplication()
If RootWorkItem.Services.Get(Of XMLWrapper)().LoadPartCentreID.Equals(UInt16.MinValue) Then
RaiseEvent NavigateToSmartPart(Me, New GenericEventArgs(Of SmartPart)(RootWorkItem.SmartParts.Get(Of ViewPartCentre).First))
Else
RaiseEvent NavigateToSmartPart(Me, New GenericEventArgs(Of SmartPart)(RootWorkItem.SmartParts.Get(Of ViewSplash).First))
End If
End Sub
<EventSubscription(EventNames.Navigate, ThreadOption.Caller)> _
Public Sub NavigateSmartPart(Of T As SmartPart)()
'Public Sub NavigateSmartPart(Of T As SmartPart)()
workspace.Show(RootWorkItem.SmartParts.Get(Of t).First)
End Sub
End Class
I am developing a Vb.net .Net 3.5 PDA application using the OpenNetCF IOC framework. I have set up and event to handle the navigation through the smart parts but when I raise the event the EventSubscription does not fire.
I am sure I have missed something simple but would appreciate so advice.
Imports OpenNETCF
Imports OpenNETCF.IoC
Imports OpenNETCF.IoC.UI
Public Class MainContainer
<EventPublication(EventNames.Navigate)> _
Public Event NavigateToSmartPart As EventHandler(Of GenericEventArgs(Of SmartPart))
Public Sub New()
' This call is required by the Windows Form Designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
RootWorkItem.Items.Add(workspace, WorkspaceNames.StackWorkspace)
RootWorkItem.Services.AddOnDemand(Of XMLWrapper)()
RootWorkItem.Services.AddOnDemand(Of DataInterface)()
'RootWorkItem.SmartParts.AddNewDisposable(Of ViewCamera)()
RootWorkItem.SmartParts.AddNew(Of ViewGoodInInspection)()
RootWorkItem.SmartParts.AddNew(Of ViewLogon)()
RootWorkItem.SmartParts.AddNew(Of ViewPartCentre)()
RootWorkItem.SmartParts.AddNew(Of ViewSplash)()
End Sub
Private Sub MainContainer_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
RootWorkItem.Services.Get(Of DataInterface)().InitialseApplication()
If RootWorkItem.Services.Get(Of XMLWrapper)().LoadPartCentreID.Equals(UInt16.MinValue) Then
RaiseEvent NavigateToSmartPart(Me, New GenericEventArgs(Of SmartPart)(RootWorkItem.SmartParts.Get(Of ViewPartCentre).First))
Else
RaiseEvent NavigateToSmartPart(Me, New GenericEventArgs(Of SmartPart)(RootWorkItem.SmartParts.Get(Of ViewSplash).First))
End If
End Sub
<EventSubscription(EventNames.Navigate, ThreadOption.Caller)> _
Public Sub NavigateSmartPart(Of T As SmartPart)()
'Public Sub NavigateSmartPart(Of T As SmartPart)()
workspace.Show(RootWorkItem.SmartParts.Get(Of t).First)
End Sub
End Class
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好吧,想通了。
这是为了满足启动对象是 Sub Main 并且该类继承自 SmartClientApplication(Of Form) 的要求。
它需要这样才能允许项目、智能部件和服务正确连接事件。
菲尔
Ok, figured it out.
It was do to a requirement that the startup object is Sub Main and that class inherits from SmartClientApplication(Of Form).
It requires this in order to allow the items, smart parts and services to wire up the event correctly.
Phil
感谢克里斯的回复,
我在创建具有 EventPublication 设置的新智能部件时也收到一条错误消息。
MAIN FORM
NEW SMART PART
它在 else if (ctors.Count() == 1) 行的以下方法中抛出目标调用错误(内部异常 NullReferenceException)。
调用堆栈
如果我从事件中删除 EventPublication 属性,则智能部分将成功创建。
Thanks for the response Chris,
I am also getting an error message when creating new smart parts that have EventPublication setup.
MAIN FORM
NEW SMART PART
Its throwing a Target Invokation error (Inner Exception NullReferenceException) in the below method on the else if (ctors.Count() == 1) line.
Call stack
If I remove the EventPublication attribute from the event then the smart part is created successfully.