A is Popupnot configurable by default, and even if it is customizable, you should have something else that you can focus on the popup, and then focus it or give it focus so that it receives a keyboard event.
In other words, if you want a keyboard event from to Popupuse Focusable="True"and place a controlled control like TextBoxeither Buttonor ListBoxand or to allow the user to give him focus by clicking on it or manually use it Focus()from the code. If you do all this, then it PreviewKeyDownshould work for Popup.
Here is a small demo program with a toggle button that opens Popup, and it shows that the slider is incremented whenever we get an event PreviewKeyDownon Popup:
<Grid>
<StackPanel>
<Slider Name="slider1"/>
<ToggleButton x:Name="toggleButton1"
Content="Open Popup"/>
</StackPanel>
<Popup PlacementTarget="{Binding ElementName=toggleButton1}"
IsOpen="{Binding IsChecked, ElementName=toggleButton1, Mode=OneWay}"
Focusable="True">
<i:Interaction.Triggers>
<i:EventTrigger EventName="PreviewKeyDown">
<ei:ChangePropertyAction TargetObject="{Binding ElementName=slider1}"
PropertyName="Value"
Value="1"
Increment="True"/>
</i:EventTrigger>
</i:Interaction.Triggers>
<TextBox Background="White"
Focusable="True">
<TextBox.Text>Sample Popup content.</TextBox.Text>
</TextBox>
</Popup>
</Grid>
source
share