我正在使用xceed wpf工具包。 因爲我在使用ChildWindow。我需要在退出鍵按下時關閉打開的子窗口。這裏是代碼關閉xceed在逃生按鈕上的子窗口點擊
<xctk:ChildWindow x:Name="ChildVendorsEdit" IsModal="True" WindowStartupLocation="Center" Caption="Edit" >
//My Content Here
</xctk:ChildWindow>
你能幫我嗎?
我正在使用xceed wpf工具包。 因爲我在使用ChildWindow。我需要在退出鍵按下時關閉打開的子窗口。這裏是代碼關閉xceed在逃生按鈕上的子窗口點擊
<xctk:ChildWindow x:Name="ChildVendorsEdit" IsModal="True" WindowStartupLocation="Center" Caption="Edit" >
//My Content Here
</xctk:ChildWindow>
你能幫我嗎?
如果您使用2.0.0或更高版本,則應將ChildWindow
放入WindowContainer
並使用PreviewKeyDown
事件。
XAML:
<xctk:WindowContainer>
<xctk:ChildWindow x:Name="ChildVendorsEdit" IsModal="True" WindowStartupLocation="Center" Caption="Edit"
PreviewKeyDown="ChildVendorsEdit_PreviewKeyDown" >
</xctk:ChildWindow>
</xctk:WindowContainer>
代碼隱藏:
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;
}
}
如果使用低於版本2.0.0,你應該使用PreviewKeyDown
事件:
XAML:
<xctk:ChildWindow x:Name="ChildVendorsEdit" IsModal="True" WindowStartupLocation="Center" Caption="Edit"
PreviewKeyDown="ChildVendorsEdit_PreviewKeyDown" >
</xctk:ChildWindow>
代碼隱藏:
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;
}
}
要PreviewKeyDown
事件處理程序關閉ChildWindow
你有兩種選擇:
WindowState
到Closed
,Close
方法。在按鈕上使用「IsCancel」屬性。
<Button Content="Discard" Click="ButtonDiscard_OnClick" IsCancel="True"></Button>
同爲ISDEFAULT(回車鍵)