In WPF I wanted to create a custom tooltip that, when open, could detect F1 key press, to take the user to a more detailed help file.
For reusability, my approach is to create a UserControl
as a tooltip. The control will detect the KeyDown
event and then execute a bindable Command
.
But in practice the KeyDown
event never appears to fire. Maybe Tooltips are not focusable for keyboard events? I have tried setting the KeyDown
event for the UserControl
, then for child controls inside the UserControl
, no luck either way.
Here is (one example) of UserControl with KeyDown event:
<UserControl x:Class="HotKeyToolTip"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
KeyDown="UserControl_KeyDown">
Here is an example of how this control would be declared as a tooltip, in this case for the items of a combobox:
<ComboBox.ItemContainerStyle>
<Style>
<Setter Property="Control.ToolTip">
<Setter.Value>
<local:HotKeyToolTip Focusable="True"/>
</Setter.Value>
</Setter>
</Style>
</ComboBox.ItemContainerStyle>