protected virtual void HandleCloseSubscription(object window, object data, EventHandler<UICompletedEventArgs> completedProc, bool isModal)
{
var dynamicEventListener = new DynamicEventListener(window, "Closed");
EventHandler closed = null;
closed = (sender, e) =>
{
bool? dialogResult = null;
PropertyHelper.TryGetPropertyValue(window, "DialogResult", out dialogResult);
completedProc(this, new UICompletedEventArgs(data, isModal ? dialogResult : null));
#if SILVERLIGHT
if (window is ChildWindow)
{
// Due to a bug in the latest version of the Silverlight toolkit, set parent to enabled again
// TODO: After every toolkit release, check if this code can be removed
Application.Current.RootVisual.SetValue(Control.IsEnabledProperty, true);
}
#endif
dynamicEventListener.EventOccurred -= closed;
dynamicEventListener.UnsubscribeFromEvent();
};
dynamicEventListener.EventOccurred += closed;
}