public void OnClosed(ViewModelClosedEventArgs e)
        {
            var handler = Closed;

            if (handler != null)
            {
                handler(this, e);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Called when a view model is closed.
        /// </summary>
        /// <param name="sender">The view model</param>
        /// <param name="e">The event args</param>
        private Task ViewModelOnClosedAsync(object sender, ViewModelClosedEventArgs e)
        {
            var viewModel = (IViewModel)sender;

            viewModel.ClosedAsync -= ViewModelOnClosedAsync;
            Deactivate(viewModel);

            return(TaskHelper.Completed);
        }
Exemplo n.º 3
0
        private async Task PlotViewModel_ClosedAsync(object sender, ViewModelClosedEventArgs e)
        {
            PlotViewModel pvm = e.ViewModel as PlotViewModel;

            if (pvm == null)
            {
                return;
            }
            Plots.Remove(pvm.PlotModel);
        }
Exemplo n.º 4
0
        private async Task OnViewModelClosed(object sender, ViewModelClosedEventArgs e)
        {
            var vm = ViewModel;

            if (vm != null)
            {
                vm.ClosedAsync -= OnViewModelClosed;
            }

            Closed.Invoke(sender, e);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Called when the <see cref="LogicBase.ViewModel"/> is closed.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="Catel.MVVM.ViewModelClosedEventArgs"/> instance containing the event data.</param>
        public override void OnViewModelClosed(object sender, ViewModelClosedEventArgs e)
        {
            if (_closeInitiatedByViewModel == null)
            {
                _closeInitiatedByViewModel       = true;
                _closeInitiatedByViewModelResult = e.Result;
            }

            base.OnViewModelClosed(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);
                }
                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();
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Called when the <see cref="LogicBase.ViewModel"/> is closed.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="Catel.MVVM.ViewModelClosedEventArgs"/> instance containing the event data.</param>
        public override async Task OnViewModelClosedAsync(object sender, ViewModelClosedEventArgs e)
        {
            if (_closeInitiatedByViewModel is null)
            {
                _closeInitiatedByViewModel       = true;
                _closeInitiatedByViewModelResult = e.Result;
            }

            await base.OnViewModelClosedAsync(sender, e);

            if (_closeInitiatedByViewModelResult != null)
            {
                var result = false;

                // If window is null, we are assuming it's a custom window based on FrameworkElement (similar to Silverlight). In that case,
                // keep using the old logic
                var window             = TargetWindow as System.Windows.Window;
                var canSetDialogResult = window?.CanSetDialogResult() ?? true;
                if (canSetDialogResult)
                {
                    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)
                {
                    if (canSetDialogResult)
                    {
                        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();
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Called when the <see cref="LogicBase.ViewModel"/> is closed.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="Catel.MVVM.ViewModelClosedEventArgs"/> instance containing the event data.</param>
        public override async Task OnViewModelClosedAsync(object sender, ViewModelClosedEventArgs e)
        {
            if (_closeInitiatedByViewModel is null)
            {
                _closeInitiatedByViewModel       = true;
                _closeInitiatedByViewModelResult = e.Result;
            }

            await base.OnViewModelClosedAsync(sender, e);

            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();
            }
        }
 private void CloseableViewModelOnClosed(object sender, ViewModelClosedEventArgs args)
 {
     if (_ignoreCloseFromViewModel)
     {
         return;
     }
     _threadManager.InvokeOnUiThreadAsync(() =>
     {
         try
         {
             _closedFromViewModel = true;
             if (NavigationService.CanGoBack)
             {
                 NavigationService.GoBack();
             }
         }
         finally
         {
             _closedFromViewModel = false;
         }
     });
 }
 private void CloseableViewModelOnClosed(ICloseableViewModel sender, ViewModelClosedEventArgs e)
 {
     _threadManager.Invoke(ExecutionMode.AsynchronousOnUiThread, this, NavigationService, e,
                           (provider, service, args) =>
     {
         if (ReferenceEquals(provider._closingViewModel, args.ViewModel))
         {
             return;
         }
         try
         {
             provider._closedFromViewModel = true;
             if (service.TryClose(args.ViewModel, args.Parameter as IDataContext))
             {
                 OnViewModelClosed(args.ViewModel, args.Parameter, provider, true);
             }
         }
         finally
         {
             provider._closedFromViewModel = false;
         }
     });
 }
 private void ViewModelOnClosed(ICloseableViewModel sender, ViewModelClosedEventArgs args)
 {
     RaiseClosed(args.Parameter);
 }
Exemplo n.º 11
0
 protected virtual void OnViewModelClosed(object sender, ViewModelClosedEventArgs e)
 {
 }
Exemplo n.º 12
0
 public void OnPublicEvent(object sender, ViewModelClosedEventArgs e)
 {
     PublicEventCounter++;
 }
Exemplo n.º 13
0
 private void OnViewModelClosed(ViewModelClosedEventArgs args)
 {
     ItemsSource.Remove(args.ViewModel);
 }
 private void CloseableViewModelOnClosed(ICloseableViewModel sender, ViewModelClosedEventArgs e)
 {
     TryCloseViewModel(e.ViewModel, e.Parameter);
 }
Exemplo n.º 15
0
 private async Task ViewModelClosedAsync(object sender, ViewModelClosedEventArgs e)
 {
     Close();
 }
 private void OnClosed(object sender, ViewModelClosedEventArgs args)
 {
     OnClosed(args.Parameter);
 }
Exemplo n.º 17
0
 /// <summary>
 /// Called when the <see cref="ViewModel" /> has been closed.
 /// </summary>
 /// <param name="sender">The sender.</param>
 /// <param name="e">The <see cref="System.EventArgs" /> instance containing the event data.</param>
 protected virtual Task OnViewModelClosedAsync(object sender, ViewModelClosedEventArgs e) => Task.CompletedTask;
Exemplo n.º 18
0
 /// <summary>
 /// Called when the <see cref="ViewModel"/> has been closed.
 /// </summary>
 /// <param name="sender">The sender.</param>
 /// <param name="e">The <see cref="Catel.MVVM.ViewModelClosedEventArgs"/> instance containing the event data.</param>
 public virtual Task OnViewModelClosedAsync(object sender, ViewModelClosedEventArgs e)
 {
     ViewModelClosed.SafeInvoke(this, e);
     return ViewModelClosedAsync.SafeInvokeAsync(this, e);
 }
Exemplo n.º 19
0
        private Task OnClosedAsync(object sender, ViewModelClosedEventArgs args)
        {
            Close();

            return(TaskHelper.Completed);
        }
Exemplo n.º 20
0
        /// <summary>
        /// Called when the <see cref="LogicBase.ViewModel"/> is closed.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="Catel.MVVM.ViewModelClosedEventArgs"/> instance containing the event data.</param>
        public override void OnViewModelClosed(object sender, ViewModelClosedEventArgs e)
        {
            if (_closeInitiatedByViewModel == null)
            {
                _closeInitiatedByViewModel = true;
                _closeInitiatedByViewModelResult = e.Result;
            }

            base.OnViewModelClosed(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 ((_closeInitiatedByViewModel ?? false) && (_closeInitiatedByViewModelResult != null))
            {
                // Support all windows (even those that do not derive from ChildWindow)
                if (!PropertyHelper.TrySetPropertyValue(TargetWindow, "DialogResult", _closeInitiatedByViewModelResult))
                {
                    Log.Warning("Failed to set the 'DialogResult' property of window type '{0}'", TargetWindow.GetType().Name);
                }
                else if (ForceCloseAfterSettingDialogResult)
                {
                    InvokeCloseDynamically();
                }
            }
            else
            {
                InvokeCloseDynamically();
            }
        }
Exemplo n.º 21
0
 private async Task OnWrappedViewModelClosedAsync(object s, ViewModelClosedEventArgs e)
 {
     await this.CloseViewModelAsync(e.Result);
 }
Exemplo n.º 22
0
 private void ViewModelClosed(object sender, ViewModelClosedEventArgs e)
 {
     Close();
 }
Exemplo n.º 23
0
 protected virtual void OnViewModelClosed(object sender, ViewModelClosedEventArgs e)
 {
 }
Exemplo n.º 24
0
        /// <summary>
        /// Called when the <see cref="ViewModel"/> has been closed.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>

        protected virtual Task OnViewModelClosedAsync(object sender, ViewModelClosedEventArgs e)
        {
            return(TaskHelper.Completed);
        }
Exemplo n.º 25
0
 /// <summary>
 /// Called when the <see cref="ViewModel"/> has been closed.
 /// </summary>
 /// <param name="sender">The sender.</param>
 /// <param name="e">The <see cref="Catel.MVVM.ViewModelClosedEventArgs"/> instance containing the event data.</param>
 public virtual void OnViewModelClosed(object sender, ViewModelClosedEventArgs e)
 {
     ViewModelClosed.SafeInvoke(this, e);
 }
Exemplo n.º 26
0
        /// <summary>
        /// Called when the <see cref="LogicBase.ViewModel"/> is closed.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="Catel.MVVM.ViewModelClosedEventArgs"/> instance containing the event data.</param>
        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);
                }
                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();
            }
        }
Exemplo n.º 27
0
 /// <summary>
 /// Called when the <see cref="ViewModel"/> has been closed.
 /// </summary>
 /// <param name="sender">The sender.</param>
 /// <param name="e">The <see cref="Catel.MVVM.ViewModelClosedEventArgs"/> instance containing the event data.</param>
 public virtual void OnViewModelClosed(object sender, ViewModelClosedEventArgs e)
 {
     ViewModelClosed.SafeInvoke(this, e);
 }
Exemplo n.º 28
0
 private Task ViewModelClosed(object sender, ViewModelClosedEventArgs e)
 {
     Close();
     return(Task.CompletedTask);
 }
Exemplo n.º 29
0
 /// <summary>
 /// Called when the <see cref="ViewModel"/> has been closed.
 /// </summary>
 /// <param name="sender">The sender.</param>
 /// <param name="e">The <see cref="Catel.MVVM.ViewModelClosedEventArgs"/> instance containing the event data.</param>
 public virtual Task OnViewModelClosedAsync(object sender, ViewModelClosedEventArgs e)
 {
     return(ViewModelClosedAsync.SafeInvokeAsync(this, e));
 }
Exemplo n.º 30
0
 /// <summary>
 /// Called when the <see cref="ViewModel"/> has been closed.
 /// </summary>
 /// <param name="sender">The sender.</param>
 /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
 
 protected virtual Task OnViewModelClosedAsync(object sender, ViewModelClosedEventArgs e)
 {
     return TaskHelper.Completed;
 }
Exemplo n.º 31
0
 private async Task ViewModelClosedAsync(object sender, ViewModelClosedEventArgs e)
 {
     Close();
 }