public override async Task OnViewModelClosedAsync(object sender, ViewModelClosedEventArgs e)
{
if (_closeInitiatedByViewModel == null)
{
_closeInitiatedByViewModel = true;
_closeInitiatedByViewModelResult = e.Result;
}
await base.OnViewModelClosedAsync(sender, e);
#if SILVERLIGHT
if (TargetWindow is ChildWindow)
{
// This code is implemented due to a bug in the ChildWindow of silverlight, see:
// http://silverlight.codeplex.com/workitem/7935
// Only handle this once
if (_isClosed)
{
return;
}
}
#endif
if (_closeInitiatedByViewModelResult != null)
{
bool result;
try
{
result = PropertyHelper.TrySetPropertyValue(TargetWindow, "DialogResult", _closeInitiatedByViewModelResult, true);
}
catch (Exception ex)
{
Log.Warning("Failed to set the 'DialogResult' exception: {0}", ex);
result = false;
}
// Support all windows (even those that do not derive from ChildWindow)
if (!result)
{
Log.Warning("Failed to set the 'DialogResult' property of window type '{0}', closing window via method", TargetWindow.GetType().Name);
InvokeCloseDynamically();
}
else if (ForceCloseAfterSettingDialogResult)
{
InvokeCloseDynamically();
}
}
else
{
InvokeCloseDynamically();
}
}