Monday, December 07, 2009

 

Keyboard focus for a UserControl

I found that getting a UserControl to fire keyboard events takes a bit of extra effort if the UserControl does not contain any buttons, textboxes, or other controls which can gain focus.

One sloppy way to accomplish this is to include a <Button /> or other control which isn't seen. Yet, as documented here, the property of a focusable element that enables this, IsTabStop, can be flagged on the UserControl itself:
<UserControl x:Class="Experiment"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
KeyDown="Experiment_KeyDown" IsTabStop="True" >

Labels: , ,


This page is powered by Blogger. Isn't yours?

Subscribe to Posts [Atom]