/// <summary>Dispose TaskDialog Resources</summary> /// <param name="disposing">If true, indicates that this is being called via Dispose rather than via the finalizer.</param> public void Dispose(bool disposing) { if (!disposed) { disposed = true; if (disposing) { // Clean up managed resources. if (nativeDialog != null && nativeDialog.ShowState == DialogShowState.Showing) { nativeDialog.NativeClose(TaskDialogResult.Cancel); } buttons = null; radioButtons = null; commandLinks = null; } // Clean up unmanaged resources SECOND, NTD counts on being closed before being disposed. if (nativeDialog != null) { nativeDialog.Dispose(); nativeDialog = null; } if (staticDialog != null) { staticDialog.Dispose(); staticDialog = null; } } }
/// <summary>Constructs the dialog result.</summary> /// <param name="native">The native task dialog</param> /// <returns>The <c>TaskDialogResults</c>.</returns> static TaskDialogResult ConstructDialogResult(NativeTaskDialog native) { Debug.Assert( native.ShowState == DialogShowState.Closed, "dialog result being constructed for unshown dialog."); TaskDialogResult result; TaskDialogStandardButtons standardButton = MapButtonIdToStandardButton(native.SelectedButtonId); // If returned ID isn't a standard button, let's fetch if (standardButton == TaskDialogStandardButtons.None) { result = TaskDialogResult.CustomButtonClicked; } else { result = (TaskDialogResult)standardButton; } return(result); }
/// <summary>Shows the core dialog</summary> /// <returns>Returns the result of the <c>TaskDialog</c>.</returns> TaskDialogResult ShowCore() { TaskDialogResult result; try { // Populate control lists, based on current contents - note we are somewhat late-bound on our control // lists, to support XAML scenarios. SortDialogControls(); // First, let's make sure it even makes sense to try a show. ValidateCurrentDialogSettings(); // Create settings object for new dialog, based on current state. var settings = new NativeTaskDialogSettings(); ApplyCoreSettings(settings); ApplySupplementalSettings(settings); // Show the dialog. NOTE: this is a BLOCKING call; the dialog proc callbacks will be executed by the // same thread as the Show() call before the thread of execution contines to the end of this method. nativeDialog = new NativeTaskDialog(settings, this); nativeDialog.NativeShow(); // Build and return dialog result to public API - leaving it null after an exception is thrown is fine // in this case result = ConstructDialogResult(nativeDialog); footerCheckBoxChecked = nativeDialog.CheckBoxChecked; } finally { CleanUp(); nativeDialog = null; } return(result); }