|
| 1 | +using System.ComponentModel; |
| 2 | + |
| 3 | +namespace DevWinUI; |
| 4 | +public static partial class ContentDialogWindowedExtensions |
| 5 | +{ |
| 6 | + extension(ContentDialog contentDialog) |
| 7 | + { |
| 8 | + public async Task<ContentDialogResult> ShowAsWindowAsync(TypedEventHandler<WindowedContentDialog, CancelEventArgs>? primaryClick = null, TypedEventHandler<WindowedContentDialog, CancelEventArgs>? secondaryClick = null, TypedEventHandler<WindowedContentDialog, CancelEventArgs>? closeClick = null) |
| 9 | + { |
| 10 | + return await ShowAsWindowAsync(contentDialog, null, true, true); |
| 11 | + } |
| 12 | + public async Task<ContentDialogResult> ShowAsWindowAsync(bool isModal, TypedEventHandler<WindowedContentDialog, CancelEventArgs>? primaryClick = null, TypedEventHandler<WindowedContentDialog, CancelEventArgs>? secondaryClick = null, TypedEventHandler<WindowedContentDialog, CancelEventArgs>? closeClick = null) |
| 13 | + { |
| 14 | + return await ShowAsWindowAsync(contentDialog, null, isModal, true); |
| 15 | + } |
| 16 | + public async Task<ContentDialogResult> ShowAsWindowAsync(Window? ownerWindow, TypedEventHandler<WindowedContentDialog, CancelEventArgs>? primaryClick = null, TypedEventHandler<WindowedContentDialog, CancelEventArgs>? secondaryClick = null, TypedEventHandler<WindowedContentDialog, CancelEventArgs>? closeClick = null) |
| 17 | + { |
| 18 | + return await ShowAsWindowAsync(contentDialog, ownerWindow, true, true); |
| 19 | + } |
| 20 | + public async Task<ContentDialogResult> ShowAsWindowAsync(Window? ownerWindow, bool isModal, TypedEventHandler<WindowedContentDialog, CancelEventArgs>? primaryClick = null, TypedEventHandler<WindowedContentDialog, CancelEventArgs>? secondaryClick = null, TypedEventHandler<WindowedContentDialog, CancelEventArgs>? closeClick = null) |
| 21 | + { |
| 22 | + return await ShowAsWindowAsync(contentDialog, ownerWindow, isModal, true); |
| 23 | + } |
| 24 | + public async Task<ContentDialogResult> ShowAsWindowWithoutTitleBarAsync(TypedEventHandler<WindowedContentDialog, CancelEventArgs>? primaryClick = null, TypedEventHandler<WindowedContentDialog, CancelEventArgs>? secondaryClick = null, TypedEventHandler<WindowedContentDialog, CancelEventArgs>? closeClick = null) |
| 25 | + { |
| 26 | + return await ShowAsWindowAsync(contentDialog, null, true, false); |
| 27 | + } |
| 28 | + public async Task<ContentDialogResult> ShowAsWindowWithoutTitleBarAsync(Window? ownerWindow, TypedEventHandler<WindowedContentDialog, CancelEventArgs>? primaryClick = null, TypedEventHandler<WindowedContentDialog, CancelEventArgs>? secondaryClick = null, TypedEventHandler<WindowedContentDialog, CancelEventArgs>? closeClick = null) |
| 29 | + { |
| 30 | + return await ShowAsWindowAsync(contentDialog, ownerWindow, true, false); |
| 31 | + } |
| 32 | + public async Task<ContentDialogResult> ShowAsWindowWithoutTitleBarAsync(bool isModal, TypedEventHandler<WindowedContentDialog, CancelEventArgs>? primaryClick = null, TypedEventHandler<WindowedContentDialog, CancelEventArgs>? secondaryClick = null, TypedEventHandler<WindowedContentDialog, CancelEventArgs>? closeClick = null) |
| 33 | + { |
| 34 | + return await ShowAsWindowAsync(contentDialog, null, isModal, false); |
| 35 | + } |
| 36 | + public async Task<ContentDialogResult> ShowAsWindowWithoutTitleBarAsync(Window? ownerWindow, bool isModal, TypedEventHandler<WindowedContentDialog, CancelEventArgs>? primaryClick = null, TypedEventHandler<WindowedContentDialog, CancelEventArgs>? secondaryClick = null, TypedEventHandler<WindowedContentDialog, CancelEventArgs>? closeClick = null) |
| 37 | + { |
| 38 | + return await ShowAsWindowAsync(contentDialog, ownerWindow, isModal, false); |
| 39 | + } |
| 40 | + public async Task<ContentDialogResult> ShowAsWindowAsync(Window? ownerWindow, bool isModal, bool hasTitleBar, TypedEventHandler<WindowedContentDialog, CancelEventArgs>? primaryClick = null, TypedEventHandler<WindowedContentDialog, CancelEventArgs>? secondaryClick = null, TypedEventHandler<WindowedContentDialog, CancelEventArgs>? closeClick = null) |
| 41 | + { |
| 42 | + WindowedContentDialog window = new() |
| 43 | + { |
| 44 | + Title = contentDialog.Title?.ToString() ?? string.Empty, |
| 45 | + HasTitleBar = hasTitleBar, |
| 46 | + Content = contentDialog.Content, |
| 47 | + PrimaryButtonText = contentDialog.PrimaryButtonText, |
| 48 | + SecondaryButtonText = contentDialog.SecondaryButtonText, |
| 49 | + CloseButtonText = contentDialog.CloseButtonText, |
| 50 | + IsPrimaryButtonEnabled = contentDialog.IsPrimaryButtonEnabled, |
| 51 | + IsSecondaryButtonEnabled = contentDialog.IsSecondaryButtonEnabled, |
| 52 | + |
| 53 | + PrimaryButtonStyle = contentDialog.PrimaryButtonStyle, |
| 54 | + SecondaryButtonStyle = contentDialog.SecondaryButtonStyle, |
| 55 | + CloseButtonStyle = contentDialog.CloseButtonStyle, |
| 56 | + |
| 57 | + OwnerWindow = ownerWindow, |
| 58 | + RequestedTheme = contentDialog.RequestedTheme |
| 59 | + }; |
| 60 | + |
| 61 | + if (primaryClick is not null) |
| 62 | + window.PrimaryButtonClick += primaryClick; |
| 63 | + if (secondaryClick is not null) |
| 64 | + window.SecondaryButtonClick += secondaryClick; |
| 65 | + if (closeClick is not null) |
| 66 | + window.CloseButtonClick += closeClick; |
| 67 | + |
| 68 | + return await window.ShowAsync(isModal); |
| 69 | + } |
| 70 | + } |
| 71 | +} |
0 commit comments