C# 闭幕式和Catel';s MessageService,can';不要取消
我使用ExitCommand从菜单->退出关闭应用程序,我尝试在用户单击X时实现相同的退出行为 我已经在XAML中定义了这一点C# 闭幕式和Catel';s MessageService,can';不要取消,c#,wpf,catel,C#,Wpf,Catel,我使用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
<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;
}
}
public命令ExitCommand{get;private set;}
#区域导体
公共ShellViewModel(IDynamicContainer dynamicContainer,IViewModelFactory viewModelFactory)
{
this.dynamicContainer=dynamicContainer;
this.viewModelFactory=viewModelFactory;
ShowInfoCommand=新命令(ShowInfoCommandExecute);
ExitCommand=新命令(OnExitCommandExecute);
}
#端区
私有void OnExitCommandExecute(CancelEventArgs args)
{
var res=MessageBox.Show(Properties.Resources.DIALOG\u EXIT,Properties.Resources.DIALOG\u EXIT\u标题,MessageBoxButton.YesNo);
//var res=messageService.Show(Properties.Resources.DIALOG\u EXIT,Properties.Resources.DIALOG\u EXIT\u标题,
//MessageButton.YesNo,MessageImage.Question);
if(res==MessageBoxResult.Yes)
{
ICloseApplicationService closeApplicationService=this.GetServiceLocator().ResolveType();
closeApplicationService.Close();
}
其他的
{
args.Cancel=true;
}
}
如果我使用MessageBox,我可以取消关闭事件(设置args.cancel=true)。否则,如果我使用IMessageService,当我从Show获得结果时,就太晚了
我做错了什么?
谢谢,Catel中的IMessageService是异步的。我们正在考虑以另一种方式实施这一点。同时,使用INavigationService.ClosingApplication事件。当我询问用户是否要关闭时,这不会解决问题,因为即使我放置了messageService。在ClosingApplication事件中显示我将关闭应用程序,因为它再次是异步的