-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New Win32 toast notification helpers (no more shortcut needed!) #3457
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
6fcbb11
1518f28
236d1e3
568601b
9729eca
6b64b85
f385bb3
d499165
1f770c1
3800284
4363829
84b9bf3
1f0bc00
55a4332
b8917c6
dc1587c
aaba4e0
b62c968
d7cf313
efcf30e
1bfe408
a65c9cc
252bbc0
bb5b042
2463bbd
3c37592
9f084ff
9e1f362
0cc87d1
644f307
c87a371
a57ba76
0b65a73
28e7730
5a8d9b3
04a7e71
389c6e1
e8cd6f0
1b0c403
8876688
0288c06
62bc118
e94afd0
8b696d4
1e45495
bf2139d
634478d
e8f8d70
02ff3a8
3d96ba1
8956b81
f1a3f02
f9045de
305dd6f
89ed383
5c8fc1b
8efdf17
0f1bdb4
3b5dfa7
aa6e892
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,21 +15,21 @@ public enum TileSize | |
| /// <summary> | ||
| /// Small Square Tile | ||
| /// </summary> | ||
| Small = 0, | ||
| Small = 1, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Guess we'll want to document this as a breaking change too?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah true that technically could be a breaking change |
||
|
|
||
| /// <summary> | ||
| /// Medium Square Tile | ||
| /// </summary> | ||
| Medium = 1, | ||
| Medium = 2, | ||
|
|
||
| /// <summary> | ||
| /// Wide Rectangle Tile | ||
| /// </summary> | ||
| Wide = 2, | ||
| Wide = 4, | ||
|
|
||
| /// <summary> | ||
| /// Large Square Tile | ||
| /// </summary> | ||
| Large = 4 | ||
| Large = 8 | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
| // See the LICENSE file in the project root for more information. | ||
|
|
||
| #if WINDOWS_UWP | ||
|
|
||
| using Windows.Foundation; | ||
| using Windows.UI.Notifications; | ||
|
|
||
| namespace Microsoft.Toolkit.Uwp.Notifications | ||
| { | ||
| /// <summary> | ||
| /// Allows you to set additional properties on the <see cref="ToastNotification"/> object before the toast is displayed. | ||
| /// </summary> | ||
| /// <param name="toast">The toast to modify that will be displayed.</param> | ||
| public delegate void CustomizeToast(ToastNotification toast); | ||
|
|
||
| /// <summary> | ||
| /// Allows you to set additional properties on the <see cref="ToastNotification"/> object before the toast is displayed. | ||
| /// </summary> | ||
| /// <param name="toast">The toast to modify that will be displayed.</param> | ||
| /// <returns>An operation.</returns> | ||
| public delegate IAsyncAction CustomizeToastAsync(ToastNotification toast); | ||
|
|
||
| /// <summary> | ||
| /// Allows you to set additional properties on the <see cref="ScheduledToastNotification"/> object before the toast is scheduled. | ||
| /// </summary> | ||
| /// <param name="toast">The scheduled toast to modify that will be scheduled.</param> | ||
| public delegate void CustomizeScheduledToast(ScheduledToastNotification toast); | ||
|
|
||
| /// <summary> | ||
| /// Allows you to set additional properties on the <see cref="ScheduledToastNotification"/> object before the toast is scheduled. | ||
| /// </summary> | ||
| /// <param name="toast">The scheduled toast to modify that will be scheduled.</param> | ||
| /// <returns>An operation.</returns> | ||
| public delegate IAsyncAction CustomizeScheduledToastAsync(ScheduledToastNotification toast); | ||
| } | ||
|
|
||
| #endif |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,13 +8,16 @@ | |
|
|
||
| namespace Microsoft.Toolkit.Uwp.Notifications | ||
| { | ||
| #if !WINRT | ||
| #pragma warning disable SA1008 | ||
| #pragma warning disable SA1009 | ||
| /// <summary> | ||
| /// Builder class used to create <see cref="ToastContent"/> | ||
| /// </summary> | ||
| public partial class ToastContentBuilder | ||
| public | ||
| #if WINRT | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems like you're using both
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. WINDOWS_UWP refers to whether the Windows 10 APIs are available (.NET Standard has that disabled, but all the rest have that enabled). WINRT refers to whether it's compiled as a Windows Runtime Component (the format that allows C++ UWP apps to consume the APIs). |
||
| sealed | ||
| #endif | ||
| partial class ToastContentBuilder | ||
| { | ||
| private IToastActions Actions | ||
| { | ||
|
|
@@ -45,6 +48,36 @@ private IList<IToastInput> InputList | |
| } | ||
| } | ||
|
|
||
| private string SerializeArgumentsIncludingGeneric(ToastArguments arguments) | ||
| { | ||
| if (_genericArguments.Count == 0) | ||
| { | ||
| return arguments.ToString(); | ||
| } | ||
|
|
||
| foreach (var genericArg in _genericArguments) | ||
| { | ||
| if (!arguments.Contains(genericArg.Key)) | ||
| { | ||
| arguments.Add(genericArg.Key, genericArg.Value); | ||
| } | ||
| } | ||
|
|
||
| return arguments.ToString(); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Add a button to the current toast. | ||
| /// </summary> | ||
| /// <param name="content">Text to display on the button.</param> | ||
| /// <param name="activationType">Type of activation this button will use when clicked. Defaults to Foreground.</param> | ||
| /// <param name="arguments">App-defined string of arguments that the app can later retrieve once it is activated when the user clicks the button.</param> | ||
| /// <returns>The current instance of <see cref="ToastContentBuilder"/></returns> | ||
| public ToastContentBuilder AddButton(string content, ToastActivationType activationType, string arguments) | ||
| { | ||
| return AddButton(content, activationType, arguments, default); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Add a button to the current toast. | ||
| /// </summary> | ||
|
|
@@ -53,15 +86,18 @@ private IList<IToastInput> InputList | |
| /// <param name="arguments">App-defined string of arguments that the app can later retrieve once it is activated when the user clicks the button.</param> | ||
| /// <param name="imageUri">Optional image icon for the button to display (required for buttons adjacent to inputs like quick reply).</param> | ||
| /// <returns>The current instance of <see cref="ToastContentBuilder"/></returns> | ||
| public ToastContentBuilder AddButton(string content, ToastActivationType activationType, string arguments, Uri imageUri = default(Uri)) | ||
| #if WINRT | ||
| [Windows.Foundation.Metadata.DefaultOverload] | ||
| #endif | ||
| public ToastContentBuilder AddButton(string content, ToastActivationType activationType, string arguments, Uri imageUri) | ||
| { | ||
| // Add new button | ||
| ToastButton button = new ToastButton(content, arguments) | ||
| { | ||
| ActivationType = activationType | ||
| }; | ||
|
|
||
| if (imageUri != default(Uri)) | ||
| if (imageUri != default) | ||
| { | ||
| button.ImageUri = imageUri.OriginalString; | ||
| } | ||
|
|
@@ -76,17 +112,46 @@ private IList<IToastInput> InputList | |
| /// <returns>The current instance of <see cref="ToastContentBuilder"/></returns> | ||
| public ToastContentBuilder AddButton(IToastButton button) | ||
| { | ||
| if (button is ToastButton toastButton && toastButton.Content == null) | ||
| { | ||
| throw new InvalidOperationException("Content is required on button."); | ||
| } | ||
|
|
||
| // List has max 5 buttons | ||
| if (ButtonList.Count == 5) | ||
| { | ||
| throw new InvalidOperationException("A toast can't have more than 5 buttons"); | ||
| } | ||
|
|
||
| if (button is ToastButton b && b.CanAddArguments()) | ||
| { | ||
| foreach (var arg in _genericArguments) | ||
| { | ||
| if (!b.ContainsArgument(arg.Key)) | ||
| { | ||
| b.AddArgument(arg.Key, arg.Value); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| ButtonList.Add(button); | ||
|
|
||
| return this; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Add an button to the toast that will be display to the right of the input text box, achieving a quick reply scenario. | ||
| /// </summary> | ||
| /// <param name="textBoxId">ID of an existing <see cref="ToastTextBox"/> in order to have this button display to the right of the input, achieving a quick reply scenario.</param> | ||
| /// <param name="content">Text to display on the button.</param> | ||
| /// <param name="activationType">Type of activation this button will use when clicked. Defaults to Foreground.</param> | ||
| /// <param name="arguments">App-defined string of arguments that the app can later retrieve once it is activated when the user clicks the button.</param> | ||
| /// <returns>The current instance of <see cref="ToastContentBuilder"/></returns> | ||
| public ToastContentBuilder AddButton(string textBoxId, string content, ToastActivationType activationType, string arguments) | ||
| { | ||
| return AddButton(textBoxId, content, activationType, arguments, default); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Add an button to the toast that will be display to the right of the input text box, achieving a quick reply scenario. | ||
| /// </summary> | ||
|
|
@@ -96,7 +161,7 @@ public ToastContentBuilder AddButton(IToastButton button) | |
| /// <param name="arguments">App-defined string of arguments that the app can later retrieve once it is activated when the user clicks the button.</param> | ||
| /// <param name="imageUri">An optional image icon for the button to display (required for buttons adjacent to inputs like quick reply)</param> | ||
| /// <returns>The current instance of <see cref="ToastContentBuilder"/></returns> | ||
| public ToastContentBuilder AddButton(string textBoxId, string content, ToastActivationType activationType, string arguments, Uri imageUri = default(Uri)) | ||
| public ToastContentBuilder AddButton(string textBoxId, string content, ToastActivationType activationType, string arguments, Uri imageUri) | ||
| { | ||
| // Add new button | ||
| ToastButton button = new ToastButton(content, arguments) | ||
|
|
@@ -105,38 +170,70 @@ public ToastContentBuilder AddButton(IToastButton button) | |
| TextBoxId = textBoxId | ||
| }; | ||
|
|
||
| if (imageUri != default(Uri)) | ||
| if (imageUri != default) | ||
| { | ||
| button.ImageUri = imageUri.OriginalString; | ||
| } | ||
|
|
||
| return AddButton(button); | ||
| } | ||
|
|
||
| #if WINRT | ||
| /// <summary> | ||
| /// Add an input text box that the user can type into. | ||
| /// </summary> | ||
| /// <param name="id">Required ID property so that developers can retrieve user input once the app is activated.</param> | ||
| /// <returns>The current instance of <see cref="ToastContentBuilder"/></returns> | ||
| public ToastContentBuilder AddInputTextBox(string id) | ||
| { | ||
| return AddInputTextBox(id, default, default); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Add an input text box that the user can type into. | ||
| /// </summary> | ||
| /// <param name="id">Required ID property so that developers can retrieve user input once the app is activated.</param> | ||
| /// <param name="placeHolderContent">Placeholder text to be displayed on the text box when the user hasn't typed any text yet.</param> | ||
| /// <returns>The current instance of <see cref="ToastContentBuilder"/></returns> | ||
| public ToastContentBuilder AddInputTextBox(string id, string placeHolderContent) | ||
| { | ||
| return AddInputTextBox(id, placeHolderContent, default); | ||
| } | ||
| #endif | ||
|
|
||
| /// <summary> | ||
| /// Add an input text box that the user can type into. | ||
| /// </summary> | ||
| /// <param name="id">Required ID property so that developers can retrieve user input once the app is activated.</param> | ||
| /// <param name="placeHolderContent">Placeholder text to be displayed on the text box when the user hasn't typed any text yet.</param> | ||
| /// <param name="title">Title text to display above the text box.</param> | ||
| /// <returns>The current instance of <see cref="ToastContentBuilder"/></returns> | ||
| public ToastContentBuilder AddInputTextBox(string id, string placeHolderContent = default(string), string title = default(string)) | ||
| public ToastContentBuilder AddInputTextBox( | ||
| string id, | ||
| #if WINRT | ||
| string placeHolderContent, | ||
| string title) | ||
| #else | ||
| string placeHolderContent = default, | ||
| string title = default) | ||
| #endif | ||
| { | ||
| var inputTextBox = new ToastTextBox(id); | ||
|
|
||
| if (placeHolderContent != default(string)) | ||
| if (placeHolderContent != default) | ||
| { | ||
| inputTextBox.PlaceholderContent = placeHolderContent; | ||
| } | ||
|
|
||
| if (title != default(string)) | ||
| if (title != default) | ||
| { | ||
| inputTextBox.Title = title; | ||
| } | ||
|
|
||
| return AddToastInput(inputTextBox); | ||
| } | ||
|
|
||
| #if !WINRT | ||
| /// <summary> | ||
| /// Add a combo box / drop-down menu that contain options for user to select. | ||
| /// </summary> | ||
|
|
@@ -145,7 +242,7 @@ public ToastContentBuilder AddButton(IToastButton button) | |
| /// <returns>The current instance of <see cref="ToastContentBuilder"/></returns> | ||
| public ToastContentBuilder AddComboBox(string id, params (string comboBoxItemId, string comboBoxItemContent)[] choices) | ||
| { | ||
| return AddComboBox(id, default(string), choices); | ||
| return AddComboBox(id, default, choices); | ||
| } | ||
|
|
||
| /// <summary> | ||
|
|
@@ -157,7 +254,7 @@ public ToastContentBuilder AddComboBox(string id, params (string comboBoxItemId, | |
| /// <returns>The current instance of <see cref="ToastContentBuilder"/></returns> | ||
| public ToastContentBuilder AddComboBox(string id, string defaultSelectionBoxItemId, params (string comboBoxItemId, string comboBoxItemContent)[] choices) | ||
| { | ||
| return AddComboBox(id, default(string), defaultSelectionBoxItemId, choices); | ||
| return AddComboBox(id, default, defaultSelectionBoxItemId, choices); | ||
| } | ||
|
|
||
| /// <summary> | ||
|
|
@@ -185,12 +282,12 @@ public ToastContentBuilder AddComboBox(string id, string title, string defaultSe | |
| { | ||
| var box = new ToastSelectionBox(id); | ||
|
|
||
| if (defaultSelectionBoxItemId != default(string)) | ||
| if (defaultSelectionBoxItemId != default) | ||
| { | ||
| box.DefaultSelectionBoxItemId = defaultSelectionBoxItemId; | ||
| } | ||
|
|
||
| if (title != default(string)) | ||
| if (title != default) | ||
| { | ||
| box.Title = title; | ||
| } | ||
|
|
@@ -203,6 +300,7 @@ public ToastContentBuilder AddComboBox(string id, string title, string defaultSe | |
|
|
||
| return AddToastInput(box); | ||
| } | ||
| #endif | ||
|
|
||
| /// <summary> | ||
| /// Add an input option to the Toast. | ||
|
|
@@ -218,5 +316,4 @@ public ToastContentBuilder AddToastInput(IToastInput input) | |
| } | ||
| #pragma warning restore SA1008 | ||
| #pragma warning restore SA1009 | ||
| #endif | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Huh, didn't see .NET 5 previews coming for this reflection package??