如何使用 XAML 中的 WPF SystemCommands.CloseWindow?
How do I use WPF SystemCommands.CloseWindow from XAML?
我正在尝试将 WPF 命令用于简单的用户界面。我的大多数命令绑定都很好,但我不知道如何在 SystemCommands class 中使用它们。在我的 XAML 我有:
<Window.CommandBindings>
<CommandBinding Command="ApplicationCommands.New" CanExecute="NewCommandCanExecute" Executed="NewCommandExecuted"/>
<CommandBinding Command="ApplicationCommands.Open" CanExecute="OpenCommandCanExecute" Executed="OpenCommandExecuted"/>
<CommandBinding Command="ApplicationCommands.Save" CanExecute="SaveCommandCanExecute" Executed="SaveCommandExecuted"/>
<CommandBinding Command="SystemCommands.CloseWindow" CanExecute="CloseWindowCanExecute" Executed="CloseWindowExecuted"/>
</Window.CommandBindings>
ApplicationCommands 中的那些完全按预期工作,但 SystemCommand.CloseWIndow
给出错误 'The member "CloseWindow" is not recognized or is not accessible.'
我错过了什么?
RoutedCommand
属性调用CloseWindow命令:
<CommandBinding Command="SystemCommands.CloseWindowCommand" .../>
我正在尝试将 WPF 命令用于简单的用户界面。我的大多数命令绑定都很好,但我不知道如何在 SystemCommands class 中使用它们。在我的 XAML 我有:
<Window.CommandBindings>
<CommandBinding Command="ApplicationCommands.New" CanExecute="NewCommandCanExecute" Executed="NewCommandExecuted"/>
<CommandBinding Command="ApplicationCommands.Open" CanExecute="OpenCommandCanExecute" Executed="OpenCommandExecuted"/>
<CommandBinding Command="ApplicationCommands.Save" CanExecute="SaveCommandCanExecute" Executed="SaveCommandExecuted"/>
<CommandBinding Command="SystemCommands.CloseWindow" CanExecute="CloseWindowCanExecute" Executed="CloseWindowExecuted"/>
</Window.CommandBindings>
ApplicationCommands 中的那些完全按预期工作,但 SystemCommand.CloseWIndow
给出错误 'The member "CloseWindow" is not recognized or is not accessible.'
我错过了什么?
RoutedCommand
属性调用CloseWindow命令:
<CommandBinding Command="SystemCommands.CloseWindowCommand" .../>