Simulating modal dialog inside a view
Posted: 24 Jul 2017, 07:14
Hi,
I would like to simulate a modal dialog inside a view. Creating a popup panel is easy, but it is hard to handle the details.
For example, I created the following XAML:
The details I have added are as follows:
1. Added IsHitTestVisible="False" while displaying the modal dialog to avoid mouse events to be handled by the contents
2. Added KeyboardNavigation.* = "Cycle" to avoid focus to move outside the modal dialog when pressing various navigation keys (Tab, Alt-Tab, Shift-Tab)
One remaining details that I couldn't solve is how to block the Ctrl-T input binding, i.e. to avoid "SayHelloCommand" firing when the dialog is showing.
Do you have any advice ?
I would like to simulate a modal dialog inside a view. Creating a popup panel is easy, but it is hard to handle the details.
For example, I created the following XAML:
Code: Select all
<UserControl 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"
xmlns:local="clr-namespace:XamlWithBlend"
d:DesignHeight="600" d:DesignWidth="1000">
<Grid>
<!-- Input bindings to simulate hot-key commands -->
<Grid.InputBindings>
<KeyBinding Gesture="CTRL+T" Command="{Binding SayHelloCommand}"/>
</Grid.InputBindings>
<!-- Contents is here -->
<Grid IsHitTestVisible="False">
</Grid>
<!-- Modal dialog with a textbox hovering on top of contents -->
<Grid Opacity="0.5"
KeyboardNavigation.ControlTabNavigation="Cycle"
KeyboardNavigation.TabNavigation="Cycle"
KeyboardNavigation.DirectionalNavigation="Cycle">
<TextBox VerticalAlignment="Center" HorizontalAlignment="Center">Blocker</TextBox>
</Grid>
</Grid>
</UserControl>
1. Added IsHitTestVisible="False" while displaying the modal dialog to avoid mouse events to be handled by the contents
2. Added KeyboardNavigation.* = "Cycle" to avoid focus to move outside the modal dialog when pressing various navigation keys (Tab, Alt-Tab, Shift-Tab)
One remaining details that I couldn't solve is how to block the Ctrl-T input binding, i.e. to avoid "SayHelloCommand" firing when the dialog is showing.
Do you have any advice ?