How can Viewport3D receive KeyUp and KeyDown events? RRS feed

  • Question

  • Hi,

    I have a Viewport3D in my application and I want to receive the KeyUp and KeyDown events. The problem is, the Viewport does not get these events. Normally you have to set a background on a control and select it, so that it can receive key and mouse events, but a Viewport3D does not have a background.

    I tryed some things. I put a some models inside the Viewport3D. If I select one of the models, then I can get key events. But if I only hover with the mouse over the Viewport3D, the Viewport dows not get any events. Aditionally, I can not select the Viewport. If I click the Viewport it should have the focus, but it still does not get events.


    What can I do to get the key events. Someone an idea?





    Thursday, May 20, 2010 4:26 PM


  • Hi Alex,

    WPF uses routed event, a routed event is a type of event that can invoke handles on multiple listeners in an element tree, rather than just on the object that raised the event. So you can add the event handler of the KeyUp and KeyDown event in the parent elements of Viewport, for example the root Window.

    For more information about routed event please refer the link as follows:

    Hope this helps.

    Best regards,
    Linda Liu

    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    • Marked as answer by Linda Liu Friday, May 28, 2010 2:59 AM
    Tuesday, May 25, 2010 8:53 AM