Search code examples
.netvb.netwindows-ceopennetcfopennetcf.ioc

OpenNetCF.IOC event subscription not firing


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

Solution

  • 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).

    Imports OpenNETCF.IoC.UI
    
    Namespace OpenNetCF_Events_CSharp
        Public Class Startup
            Inherits SmartClientApplication(Of Form1)
    
            Public Shared Sub Main()
                Dim appStarter As New Startup
                appStarter.Start()
            End Sub
    
        End Class
    
    End Namespace
    

    It requires this in order to allow the items, smart parts and services to wire up the event correctly.

    Phil