コード例 #1
0
            /// <summary>
            /// Close was requested by the child
            /// </summary>
            /// <param name="item">Item to close</param>
            /// <param name="dialogResult">DialogResult to close with, if it's a dialog</param>
            async void IChildDelegate.CloseItem(object item, bool?dialogResult)
            {
                if (item != this.viewModel)
                {
                    logger.Warn("IChildDelegate.CloseItem called with item {0} which is _not_ our ViewModel {1}", item, this.viewModel);
                    return;
                }

                var guardClose = this.viewModel as IGuardClose;

                if (guardClose != null && !await guardClose.CanCloseAsync())
                {
                    logger.Info("Close of ViewModel {0} cancelled because CanCloseAsync returned false", this.viewModel);
                    return;
                }

                logger.Info("ViewModel {0} close requested with DialogResult {1} because it called RequestClose", this.viewModel, dialogResult);

                this.window.StateChanged -= this.WindowStateChanged;
                this.window.Closed       -= this.WindowClosed;
                this.window.Closing      -= this.WindowClosing;

                // Need to call this after unregistering the event handlers, as it causes the window
                // to be closed
                if (dialogResult != null)
                {
                    this.window.DialogResult = dialogResult;
                }

                ScreenExtensions.TryClose(this.viewModel);

                this.window.Close();
            }
コード例 #2
0
            private void WindowClosed(object sender, EventArgs e)
            {
                // Logging was done in the Closing handler

                this.window.StateChanged -= this.WindowStateChanged;
                this.window.Closed       -= this.WindowClosed;
                this.window.Closing      -= this.WindowClosing; // Not sure this is required

                ScreenExtensions.TryClose(this.viewModel);
            }
コード例 #3
0
        /// <summary>
        /// Close an item, and clear its parent if it's set to the current parent
        /// </summary>
        /// <typeparam name="T">Type of conductor</typeparam>
        /// <param name="parent">Parent</param>
        /// <param name="item">Item to close and clean up</param>
        /// <param name="dispose">True to dispose children as well as close them</param>
        public static void CloseAndCleanUp <T>(this IConductor <T> parent, T item, bool dispose)
        {
            ScreenExtensions.TryClose(item);

            var itemAsChild = item as IChild;

            if (itemAsChild != null && itemAsChild.Parent == parent)
            {
                itemAsChild.Parent = null;
            }

            if (dispose)
            {
                ScreenExtensions.TryDispose(item);
            }
        }