| | | 1 | | // ----------------------------------------------------------------------- |
| | | 2 | | // <copyright file="DialogOptions.cs" company="Stéphane ANDRE"> |
| | | 3 | | // Copyright (c) Stéphane ANDRE. All rights reserved. |
| | | 4 | | // </copyright> |
| | | 5 | | // ----------------------------------------------------------------------- |
| | | 6 | | |
| | | 7 | | namespace MyNet.UI.Dialogs.ContentDialogs; |
| | | 8 | | |
| | | 9 | | /// <summary> |
| | | 10 | | /// Represents the options for configuring a content dialog (modality, title, owner, overlay behaviour …). |
| | | 11 | | /// </summary> |
| | | 12 | | public sealed class DialogOptions |
| | | 13 | | { |
| | | 14 | | /// <summary> |
| | | 15 | | /// Gets or sets the dialog associated with these options. |
| | | 16 | | /// </summary> |
| | | 17 | | public IDialog Dialog { get; set; } = null!; |
| | | 18 | | |
| | | 19 | | /// <summary> |
| | | 20 | | /// Gets or sets a value indicating whether the dialog is modal. |
| | | 21 | | /// </summary> |
| | | 22 | | public bool IsModal { get; set; } |
| | | 23 | | |
| | | 24 | | /// <summary> |
| | | 25 | | /// Gets or sets the title override for the dialog. |
| | | 26 | | /// When set, takes precedence over <see cref="IDialog.Title"/>. |
| | | 27 | | /// </summary> |
| | | 28 | | public string? Title { get; set; } |
| | | 29 | | |
| | | 30 | | /// <summary> |
| | | 31 | | /// Gets or sets the owner of the dialog (e.g. the parent window). |
| | | 32 | | /// </summary> |
| | | 33 | | public object? Owner { get; set; } |
| | | 34 | | |
| | | 35 | | /// <summary> |
| | | 36 | | /// Gets or sets a value indicating whether clicking on the overlay closes the dialog. |
| | | 37 | | /// Defaults to <see langword="true"/>. |
| | | 38 | | /// </summary> |
| | | 39 | | public bool CloseOnOverlayClick { get; set; } = true; |
| | | 40 | | |
| | | 41 | | /// <summary> |
| | | 42 | | /// Creates a detached copy of <paramref name="options"/> bound to <paramref name="dialog"/> |
| | | 43 | | /// without mutating the caller's instance. |
| | | 44 | | /// </summary> |
| | | 45 | | /// <param name="dialog">The dialog instance to associate with the resolved options.</param> |
| | | 46 | | /// <param name="options">Optional source options; when <see langword="null"/>, defaults are used.</param> |
| | | 47 | | /// <returns>A new <see cref="DialogOptions"/> instance.</returns> |
| | | 48 | | public static DialogOptions Resolve(IDialog dialog, DialogOptions? options = null) |
| | 30 | 49 | | => options is null |
| | 30 | 50 | | ? new() { Dialog = dialog } |
| | 30 | 51 | | : new DialogOptions |
| | 30 | 52 | | { |
| | 30 | 53 | | Dialog = dialog, |
| | 30 | 54 | | IsModal = options.IsModal, |
| | 30 | 55 | | Title = options.Title, |
| | 30 | 56 | | Owner = options.Owner, |
| | 30 | 57 | | CloseOnOverlayClick = options.CloseOnOverlayClick |
| | 30 | 58 | | }; |
| | | 59 | | } |
| | | 60 | | |