Skip to main content
Home Forums Silverlight Programming Programming with .NET - General KeyDown event for Silverlight User Control
7 replies. Latest Post by forci on October 21, 2008.
(0)
RootCanvas
Member
10 points
8 Posts
02-06-2008 12:59 PM |
Hi,
I have tried several ways to track the KeyDown event on a SL User Control but not success. Does anyone can know how can we capture the key events of a user control?
Thanks,
mchlsync
Star
14606 points
2,730 Posts
02-06-2008 3:22 PM |
Hello,
AFAIK, Key input events (KeyDown and Keyup) works only for root canvas (e.g. Canvas from Page.xaml). I think it won't work for user control.
FredHirs...
Participant
928 points
165 Posts
02-06-2008 10:02 PM |
You will need to implement some additional logic to support bubbling the events to your controls... from the root canvas.
02-07-2008 12:34 PM |
Do you have any idea about how to do this, ie as you say need to implement some additional logic,
02-07-2008 6:42 PM |
I have created a FocusManager to manage the current focused control and then from the base Page class I push the events to the focus manager to send to the focused control. I also have a base control class that supports focus to manage that interaction as well.
KeyUp +=
Then the processing methods would call the appropriate FocusManager.Process***(e) to start processing the events. These handlers would simply detect if there is a focused control and if so send it the event. The focusing would simply be set when the user clicks on the control or you could get even more in depth and support tab ordering as well.
02-09-2008 1:24 PM |
Thank you both of you for replies. still i dont hv luck. could you pls give some sample code for this.
hammadmirza
324 points
107 Posts
02-10-2008 12:55 PM |
FredHirschfeld is right,
this is the only way of doing it
you can call a public method of your custom control e.g public void OnKeyDown(...)
and pass in the sender and eventargs , if the custom control is focused ( Mouse Over that control or MouseLeftButtonDown occured on it)
i also did it by this way
forci
351 points
275 Posts
10-21-2008 3:47 AM |
What if you have for root element Grid.
This behaviour is very strange for me. Only root canvas can receive keys events?
So if i understand correctly everything, in your UserControl, you must have for your root element Canvas and only this control can receive keys events?