If you use version 2.0.0 or higher you should put ChildWindow
in WindowContainer
and use PreviewKeyDown
event.
XAML:
<xctk:WindowContainer>
<xctk:ChildWindow x:Name="ChildVendorsEdit" IsModal="True" WindowStartupLocation="Center" Caption="Edit"
PreviewKeyDown="ChildVendorsEdit_PreviewKeyDown" >
</xctk:ChildWindow>
</xctk:WindowContainer>
Code-behind:
private void ChildVendorsEdit_PreviewKeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Escape)
{
(sender as Xceed.Wpf.Toolkit.ChildWindow).WindowState = Xceed.Wpf.Toolkit.WindowState.Closed;
}
}
If you use version below 2.0.0 you should use PreviewKeyDown
event:
XAML:
<xctk:ChildWindow x:Name="ChildVendorsEdit" IsModal="True" WindowStartupLocation="Center" Caption="Edit"
PreviewKeyDown="ChildVendorsEdit_PreviewKeyDown" >
</xctk:ChildWindow>
Code-behind:
private void ChildVendorsEdit_PreviewKeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Escape)
{
(sender as Xceed.Wpf.Toolkit.ChildWindow).WindowState = Xceed.Wpf.Toolkit.WindowState.Closed;
}
}
To close ChildWindow
in PreviewKeyDown
event handler you have two options:
- you can set
WindowState
to Closed
,
- or you can invoke
Close
method.