闭幕式和Catel';s消息服务,可以';t取消
本文关键字:可以 取消 服务 Catel 闭幕式 消息 | 更新日期: 2023-09-27 18:00:28
我正在使用ExitCommand从菜单->退出关闭应用程序,当用户单击X 时,我试图实现相同的退出行为
我已经在XAML 中定义了这一点
<catel:Window x:Class="IF.Tesoreria.Client.WPF.Views.ShellView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:catel="http://catel.codeplex.com"
xmlns:view="clr-namespace:IF.Tesoreria.Client.WPF.Views"
xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
Icon="../Media/threasure.gif" Height="500" Width="800" >
<i:Interaction.Triggers>
<i:EventTrigger EventName="Closing">
<catel:EventToCommand Command="{Binding ExitCommand}" PassEventArgsToCommand="True"/>
</i:EventTrigger>
</i:Interaction.Triggers>
<Grid>
<!--omiss-->
在ViewModel中,我使用了以下命令
public Command<CancelEventArgs> ExitCommand { get; private set; }
#region CTor
public ShellViewModel( IDynamicContainer dynamicContainer, IViewModelFactory viewModelFactory)
{
this.dynamicContainer = dynamicContainer;
this.viewModelFactory = viewModelFactory;
ShowInfoCommand = new Command(ShowInfoCommandExecute);
ExitCommand = new Command<CancelEventArgs>(OnExitCommandExecute);
}
#endregion
private void OnExitCommandExecute(CancelEventArgs args)
{
var res = MessageBox.Show(Properties.Resources.DIALOG_EXIT, Properties.Resources.DIALOG_EXIT_CAPTION,MessageBoxButton.YesNo);
//var res = messageService.Show(Properties.Resources.DIALOG_EXIT, Properties.Resources.DIALOG_EXIT_CAPTION,
// MessageButton.YesNo, MessageImage.Question);
if (res == MessageBoxResult.Yes)
{
ICloseApplicationService closeApplicationService = this.GetServiceLocator().ResolveType<ICloseApplicationService>();
closeApplicationService.Close();
}
else
{
args.Cancel = true;
}
}
如果我使用MessageBox,我可以取消关闭事件(设置args.cancel=true)。否则,如果我使用IMessageService,当我从Show得到结果时,已经太晚了
我做错了什么?感谢
Catel中的IMessageService是异步的。我们正在考虑以不同的方式实施这一点。同时,使用INavigationService.ClosingApplication事件。