WeakEventListener not called with .NET 3.5

Jul 9, 2012 at 9:24 AM
Edited Jul 10, 2012 at 6:47 AM

Hello,

I have to use .NET 3.5 for my application.That needed some modifications in the 3d toolkit code : first commenting all the code referring to 'manipulation' (screen touch interface, introduced in .NET 4), and then moving the cameraController.InputBindings initializations in .cs code rather than in xaml, as explained in discussion http://helixtoolkit.codeplex.com/discussions/273572.

After that, most of the mouse and keyboard interface works for pan, zoom and rotate. But rolling the mouse wheel for zoom with inertia didn't work anymore. After some search in your code, i found that the CameraController.renderingEventListener is never called (in .NET 3.5), thus failing to call OnCompositionTargetRendering and finally OnTimeStep, which implements zoom with inertia.

I fixed that problem by replacing the WeakEventLlistener with standard  handlers attached to events : for example in CameraController.cs :

private void SubscribeEvents()
        {
            this.MouseWheel += this.OnMouseWheel;
            this.KeyDown += this.OnKeyDown;
            //RenderingEventManager.AddListener(this.renderingEventListener);
            CompositionTarget.Rendering += new EventHandler(OnCompositionTargetRendering);
        }

        private void UnSubscribeEvents()
        {
            this.MouseWheel -= this.OnMouseWheel;
            this.KeyDown -= this.OnKeyDown;
       //     RenderingEventManager.RemoveListener(this.renderingEventListener);
            CompositionTarget.Rendering -= new EventHandler(OnCompositionTargetRendering);
        }

 

So it works. But using standard event handlers rather than weak events could cause in some cases memory leaks, did i learn by searching a bit about weak events (http://msdn.microsoft.com/en-us/library/aa970850.aspx).

Finally my question is : have you a clue about the reason why the renderingEventListener is not called in .NET 3.5  ?

Thanks for your work.