Skip to content

Commit 1fd7bc1

Browse files
authored
Merge branch 'master' into trigger-enum-parse
2 parents a85e699 + e407e07 commit 1fd7bc1

File tree

46 files changed

+1409
-935
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1409
-935
lines changed

Microsoft.Toolkit.Uwp.Notifications/Toasts/Builder/ToastContentBuilder.Actions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public ToastContentBuilder AddButton(string content, ToastActivationType activat
112112
/// <returns>The current instance of <see cref="ToastContentBuilder"/></returns>
113113
public ToastContentBuilder AddButton(IToastButton button)
114114
{
115-
if (button is ToastButton toastButton && toastButton.Content == null)
115+
if (button is ToastButton toastButton && toastButton.Content == null && toastButton.NeedsContent())
116116
{
117117
throw new InvalidOperationException("Content is required on button.");
118118
}

Microsoft.Toolkit.Uwp.Notifications/Toasts/ToastButton.cs

Lines changed: 92 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,17 @@ public sealed class ToastButton :
2020

2121
private bool _usingCustomArguments;
2222

23+
private bool _usingSnoozeActivation;
24+
private string _snoozeSelectionBoxId;
25+
26+
private bool _usingDismissActivation;
27+
28+
internal bool NeedsContent()
29+
{
30+
// Snooze/dismiss buttons don't need content (the system will auto-add the localized strings).
31+
return !_usingDismissActivation && !_usingSnoozeActivation;
32+
}
33+
2334
/// <summary>
2435
/// Initializes a new instance of the <see cref="ToastButton"/> class.
2536
/// </summary>
@@ -213,6 +224,11 @@ private ToastButton AddArgumentHelper(string key, string value)
213224
throw new InvalidOperationException("You cannot use the AddArgument methods when using protocol activation.");
214225
}
215226

227+
if (_usingDismissActivation || _usingSnoozeActivation)
228+
{
229+
throw new InvalidOperationException("You cannot use the AddArgument methods when using dismiss or snooze activation.");
230+
}
231+
216232
bool alreadyExists = _arguments.ContainsKey(key);
217233

218234
_arguments[key] = value;
@@ -314,6 +330,48 @@ public ToastButton SetAfterActivationBehavior(ToastAfterActivationBehavior after
314330
return this;
315331
}
316332

333+
/// <summary>
334+
/// Configures the button to use system snooze activation when the button is clicked, using the default system snooze time.
335+
/// </summary>
336+
/// <returns>The current instance of <see cref="ToastButton"/></returns>
337+
public ToastButton SetSnoozeActivation()
338+
{
339+
return SetSnoozeActivation(null);
340+
}
341+
342+
/// <summary>
343+
/// Configures the button to use system snooze activation when the button is clicked, with a snooze time defined by the specified selection box.
344+
/// </summary>
345+
/// <param name="selectionBoxId">The ID of an existing <see cref="ToastSelectionBox"/> which allows the user to pick a custom snooze time. The ID's of the <see cref="ToastSelectionBoxItem"/>s inside the selection box must represent the snooze interval in minutes. For example, if the user selects an item that has an ID of "120", then the notification will be snoozed for 2 hours. When the user clicks this button, if you specified a SelectionBoxId, the system will parse the ID of the selected item and snooze by that amount of minutes.</param>
346+
/// <returns>The current instance of <see cref="ToastButton"/></returns>
347+
public ToastButton SetSnoozeActivation(string selectionBoxId)
348+
{
349+
if (_arguments.Count > 0)
350+
{
351+
throw new InvalidOperationException($"{nameof(SetSnoozeActivation)} cannot be used in conjunction with ${nameof(AddArgument)}.");
352+
}
353+
354+
_usingSnoozeActivation = true;
355+
_snoozeSelectionBoxId = selectionBoxId;
356+
357+
return this;
358+
}
359+
360+
/// <summary>
361+
/// Configures the button to use system dismiss activation when the button is clicked (the toast will simply dismiss rather than activating).
362+
/// </summary>
363+
/// <returns>The current instance of <see cref="ToastButton"/></returns>
364+
public ToastButton SetDismissActivation()
365+
{
366+
if (_arguments.Count > 0)
367+
{
368+
throw new InvalidOperationException($"{nameof(SetDismissActivation)} cannot be used in conjunction with ${nameof(AddArgument)}.");
369+
}
370+
371+
_usingDismissActivation = true;
372+
return this;
373+
}
374+
317375
/// <summary>
318376
/// Sets an identifier used in telemetry to identify your category of action. This should be something like "Delete", "Reply", or "Archive". In the upcoming toast telemetry dashboard in Dev Center, you will be able to view how frequently your actions are being clicked.
319377
/// </summary>
@@ -349,7 +407,7 @@ public ToastButton SetTextBoxId(string textBoxId)
349407

350408
internal bool CanAddArguments()
351409
{
352-
return ActivationType != ToastActivationType.Protocol && !_usingCustomArguments;
410+
return ActivationType != ToastActivationType.Protocol && !_usingCustomArguments && !_usingDismissActivation && !_usingSnoozeActivation;
353411
}
354412

355413
internal bool ContainsArgument(string key)
@@ -362,13 +420,44 @@ internal Element_ToastAction ConvertToElement()
362420
var el = new Element_ToastAction()
363421
{
364422
Content = Content,
365-
Arguments = Arguments,
366-
ActivationType = Element_Toast.ConvertActivationType(ActivationType),
367423
ImageUri = ImageUri,
368424
InputId = TextBoxId,
369425
HintActionId = HintActionId
370426
};
371427

428+
if (_usingSnoozeActivation)
429+
{
430+
el.ActivationType = Element_ToastActivationType.System;
431+
el.Arguments = "snooze";
432+
433+
if (_snoozeSelectionBoxId != null)
434+
{
435+
el.InputId = _snoozeSelectionBoxId;
436+
}
437+
438+
// Content needs to be specified as empty for auto-generated Snooze content
439+
if (el.Content == null)
440+
{
441+
el.Content = string.Empty;
442+
}
443+
}
444+
else if (_usingDismissActivation)
445+
{
446+
el.ActivationType = Element_ToastActivationType.System;
447+
el.Arguments = "dismiss";
448+
449+
// Content needs to be specified as empty for auto-generated Dismiss content
450+
if (el.Content == null)
451+
{
452+
el.Content = string.Empty;
453+
}
454+
}
455+
else
456+
{
457+
el.ActivationType = Element_Toast.ConvertActivationType(ActivationType);
458+
el.Arguments = Arguments;
459+
}
460+
372461
ActivationOptions?.PopulateElement(el);
373462

374463
return el;

Microsoft.Toolkit.Uwp.SampleApp/Microsoft.Toolkit.Uwp.SampleApp.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@
267267
<Content Include="Icons\More.png" />
268268
<Content Include="Icons\Notifications.png" />
269269
<Content Include="Icons\Services.png" />
270+
<Content Include="SamplePages\TabbedCommandBar\TabbedCommandBar.png" />
270271
<Content Include="SamplePages\Animations\Effects\FadeBehavior.png" />
271272
<Content Include="SamplePages\ColorPicker\ColorPicker.png" />
272273
<Content Include="SamplePages\TilesBrush\TilesBrush.png" />
@@ -980,6 +981,9 @@
980981
<Generator>MSBuild:Compile</Generator>
981982
<SubType>Designer</SubType>
982983
</Page>
984+
<Content Include="SamplePages\TabbedCommandBar\TabbedCommandBar.bind">
985+
<SubType>Designer</SubType>
986+
</Content>
983987
<Page Include="SamplePages\CanvasPathGeometry\CanvasPathGeometryPage.xaml">
984988
<SubType>Designer</SubType>
985989
<Generator>MSBuild:Compile</Generator>

Microsoft.Toolkit.Uwp.SampleApp/SamplePages/CanvasPathGeometry/CanvasPathGeometryPage.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
using System.Text;
99
using Microsoft.Graphics.Canvas.Geometry;
1010
using Microsoft.Graphics.Canvas.UI.Xaml;
11-
using Microsoft.Toolkit.Uwp.UI.Extensions;
11+
using Microsoft.Toolkit.Uwp.Extensions;
1212
using Microsoft.Toolkit.Uwp.UI.Media.Geometry;
1313
using Windows.System;
1414
using Windows.UI;
Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
2+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
3+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
4+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
5+
xmlns:controls="using:Microsoft.Toolkit.Uwp.UI.Controls"
6+
xmlns:converters="using:Microsoft.Toolkit.Uwp.UI.Converters"
7+
mc:Ignorable="d">
8+
<Page.Resources>
9+
<converters:VisibilityToBoolConverter x:Key="VisBoolConverter"/>
10+
</Page.Resources>
11+
<Grid>
12+
<Grid.RowDefinitions>
13+
<RowDefinition Height="Auto"/>
14+
<RowDefinition/>
15+
</Grid.RowDefinitions>
16+
17+
<controls:TabbedCommandBar>
18+
<controls:TabbedCommandBar.PaneFooter>
19+
<CommandBar Background="Transparent" DefaultLabelPosition="Right">
20+
<AppBarButton Label="Share" Icon="Share"/>
21+
<AppBarButton Label="Comments" Icon="Message"/>
22+
</CommandBar>
23+
</controls:TabbedCommandBar.PaneFooter>
24+
<controls:TabbedCommandBar.MenuItems>
25+
<controls:TabbedCommandBarItem Header="Home">
26+
<AppBarButton Icon="Undo" Label="Undo"/>
27+
<AppBarButton Icon="Redo" Label="Redo"/>
28+
<AppBarButton Icon="Paste" Label="Paste"/>
29+
<AppBarSeparator />
30+
<AppBarElementContainer>
31+
<controls:ColorPickerButton SelectedColor="{ThemeResource Brand-Color}"/>
32+
</AppBarElementContainer>
33+
<AppBarElementContainer>
34+
<ComboBox SelectedIndex="0" MinWidth="175">
35+
<ComboBoxItem Content="Arial" />
36+
<ComboBoxItem Content="Calibri" />
37+
<ComboBoxItem Content="JetBrains Mono" />
38+
<ComboBoxItem Content="Roboto" />
39+
<ComboBoxItem Content="Sergio UI" />
40+
<ComboBoxItem Content="Sergio UI Semibold" />
41+
</ComboBox>
42+
</AppBarElementContainer>
43+
<AppBarElementContainer>
44+
<TextBox PlaceholderText="Size"/>
45+
</AppBarElementContainer>
46+
<AppBarToggleButton Icon="Bold" Label="Bold" />
47+
<AppBarToggleButton Icon="Italic" Label="Italic" />
48+
<AppBarToggleButton Icon="Underline" Label="Underline" />
49+
</controls:TabbedCommandBarItem>
50+
<controls:TabbedCommandBarItem Header="Insert">
51+
<AppBarButton Icon="Pictures" Label="Pictures">
52+
<AppBarButton.Flyout>
53+
<MenuFlyout Placement="BottomEdgeAlignedLeft">
54+
<MenuFlyoutItem Text="This Device">
55+
<MenuFlyoutItem.Icon>
56+
<FontIcon FontFamily="{ThemeResource SymbolThemeFontFamily}" Glyph="&#xEC4E;" />
57+
</MenuFlyoutItem.Icon>
58+
</MenuFlyoutItem>
59+
<MenuFlyoutItem Text="Stock Images">
60+
<MenuFlyoutItem.Icon>
61+
<FontIcon FontFamily="{ThemeResource SymbolThemeFontFamily}" Glyph="&#xE721;" />
62+
</MenuFlyoutItem.Icon>
63+
</MenuFlyoutItem>
64+
<MenuFlyoutItem Icon="Globe" Text="Online Pictures" />
65+
</MenuFlyout>
66+
</AppBarButton.Flyout>
67+
</AppBarButton>
68+
<AppBarButton Label="Shapes">
69+
<AppBarButton.Icon>
70+
<FontIcon FontFamily="Segoe UI Symbol" Glyph="&#x25A1;" />
71+
</AppBarButton.Icon>
72+
</AppBarButton>
73+
<AppBarButton Label="Icons">
74+
<AppBarButton.Icon>
75+
<FontIcon FontFamily="{ThemeResource SymbolThemeFontFamily}" Glyph="&#xED58;" />
76+
</AppBarButton.Icon>
77+
</AppBarButton>
78+
<AppBarButton Label="3D Models">
79+
<AppBarButton.Icon>
80+
<FontIcon FontFamily="{ThemeResource SymbolThemeFontFamily}" Glyph="&#xF158;" />
81+
</AppBarButton.Icon>
82+
</AppBarButton>
83+
<AppBarSeparator/>
84+
<AppBarButton Label="Add-ins">
85+
<AppBarButton.Icon>
86+
<FontIcon FontFamily="{ThemeResource SymbolThemeFontFamily}" Glyph="&#xECAA;" />
87+
</AppBarButton.Icon>
88+
</AppBarButton>
89+
<controls:TabbedCommandBarItem.SecondaryCommands>
90+
<AppBarButton Icon="Add" Label="New item" />
91+
</controls:TabbedCommandBarItem.SecondaryCommands>
92+
</controls:TabbedCommandBarItem>
93+
<controls:TabbedCommandBarItem x:Name="PictureFormat"
94+
Header="Picture Format"
95+
IsContextual="True"
96+
Visibility="Collapsed">
97+
<AppBarButton Label="Remove Background">
98+
<AppBarButton.Icon>
99+
<FontIcon FontFamily="{ThemeResource SymbolThemeFontFamily}" Glyph="&#xE706;" />
100+
</AppBarButton.Icon>
101+
</AppBarButton>
102+
<AppBarButton Label="Picture Effects">
103+
<AppBarButton.Icon>
104+
<FontIcon FontFamily="{ThemeResource SymbolThemeFontFamily}" Glyph="&#xF158;" />
105+
</AppBarButton.Icon>
106+
</AppBarButton>
107+
<AppBarButton Label="Rotate">
108+
<AppBarButton.Icon>
109+
<FontIcon FontFamily="{ThemeResource SymbolThemeFontFamily}" Glyph="&#xE7AD;" />
110+
</AppBarButton.Icon>
111+
</AppBarButton>
112+
<AppBarElementContainer>
113+
<SplitButton>
114+
<StackPanel Spacing="12" Orientation="Horizontal">
115+
<FontIcon FontSize="16" FontFamily="{ThemeResource SymbolThemeFontFamily}" Glyph="&#xE7A8;" />
116+
<TextBlock FontSize="12" Text="Crop"/>
117+
</StackPanel>
118+
<SplitButton.Flyout>
119+
<MenuFlyout>
120+
<MenuFlyoutItem Text="Crop">
121+
<MenuFlyoutItem.Icon>
122+
<FontIcon FontFamily="{ThemeResource SymbolThemeFontFamily}" Glyph="&#xE7A8;" />
123+
</MenuFlyoutItem.Icon>
124+
</MenuFlyoutItem>
125+
<MenuFlyoutItem Text="Crop to Shape">
126+
<MenuFlyoutItem.Icon>
127+
<FontIcon FontFamily="{ThemeResource SymbolThemeFontFamily}" Glyph="&#xF407;" />
128+
</MenuFlyoutItem.Icon>
129+
</MenuFlyoutItem>
130+
<MenuFlyoutItem Text="Aspect Ratio" />
131+
<MenuFlyoutSeparator/>
132+
<MenuFlyoutItem Text="Fill" />
133+
<MenuFlyoutItem Text="Fit" />
134+
</MenuFlyout>
135+
</SplitButton.Flyout>
136+
</SplitButton>
137+
</AppBarElementContainer>
138+
</controls:TabbedCommandBarItem>
139+
</controls:TabbedCommandBar.MenuItems>
140+
</controls:TabbedCommandBar>
141+
142+
<Grid Grid.Row="1">
143+
<ToggleSwitch x:Name="ContextualToggle" IsOn="{Binding Visibility, ElementName=PictureFormat, Converter={StaticResource VisBoolConverter}, Mode=TwoWay}"
144+
OffContent="Contextual Tab Off" OnContent="Contextual Tab On"/>
145+
</Grid>
146+
</Grid>
147+
</Page>
2.88 KB
Loading

Microsoft.Toolkit.Uwp.SampleApp/SamplePages/Toast/ToastCode.bind

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ private void PopToast()
1313
("60", "1 hour"),
1414
("240", "4 hours"),
1515
("1440", "1 day"))
16-
.AddButton(new ToastButtonSnooze() { SelectionBoxId = "snoozeTime" })
17-
.AddButton(new ToastButtonDismiss())
16+
.AddButton(new ToastButton()
17+
.SetSnoozeActivation("snoozeTime"))
18+
.AddButton(new ToastButton()
19+
.SetDismissActivation())
1820
.Show();
1921
}

Microsoft.Toolkit.Uwp.SampleApp/SamplePages/Toast/ToastPage.xaml.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,10 @@ public static ToastContent GenerateToastContent()
4040
("60", "1 hour"),
4141
("240", "4 hours"),
4242
("1440", "1 day"))
43-
.AddButton(new ToastButtonSnooze() { SelectionBoxId = "snoozeTime" })
44-
.AddButton(new ToastButtonDismiss());
43+
.AddButton(new ToastButton()
44+
.SetSnoozeActivation("snoozeTime"))
45+
.AddButton(new ToastButton()
46+
.SetDismissActivation());
4547

4648
return builder.Content;
4749
}

Microsoft.Toolkit.Uwp.SampleApp/SamplePages/XamlOnlyPage.xaml

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
44
xmlns:ani="using:Microsoft.Toolkit.Uwp.UI.Animations"
55
xmlns:behaviors="using:Microsoft.Toolkit.Uwp.UI.Behaviors"
6+
xmlns:converters="using:Microsoft.Toolkit.Uwp.UI.Converters"
67
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
78
xmlns:interactions="using:Microsoft.Xaml.Interactions.Core"
89
xmlns:interactivity="using:Microsoft.Xaml.Interactivity"
@@ -17,6 +18,8 @@
1718
<!-- Put a copy of any controls/resources required for XAML Parsing within XAML Only Samples -->
1819
<!-- This page is never loaded by the app, but used to trick the compiler... -->
1920
<Page.Resources>
21+
<converters:VisibilityToBoolConverter x:Key="VisibilityBoolConverter" />
22+
<converters:BoolToVisibilityConverter x:Key="BoolVisibilityConverter" />
2023
<triggers:CompareStateTrigger x:Key="CompareStateTrigger" />
2124
<triggers:IsEqualStateTrigger x:Key="IsEqualStateTrigger" />
2225
<triggers:IsNotEqualStateTrigger x:Key="IsNotEqualStateTrigger" />
@@ -34,17 +37,17 @@
3437
<ani:OpacityAnimation />
3538
<ani:StartAnimationActivity />
3639
<ani:InvokeActionsActivity />
37-
<ani:ClipAnimation/>
38-
<ani:BlurEffectAnimation/>
39-
<ani:SaturationEffectAnimation/>
40-
<ani:AnimationScope/>
41-
<ani:ExposureEffectAnimation/>
40+
<ani:ClipAnimation />
41+
<ani:BlurEffectAnimation />
42+
<ani:SaturationEffectAnimation />
43+
<ani:AnimationScope />
44+
<ani:ExposureEffectAnimation />
4245
</ani:AnimationSet>
4346
</ani:Explicit.Animations>
4447
<media:UIElementExtensions.VisualFactory>
4548
<media:PipelineVisualFactory>
4649
<media:OpacityEffect />
47-
<media:ExposureEffect/>
50+
<media:ExposureEffect />
4851
</media:PipelineVisualFactory>
4952
</media:UIElementExtensions.VisualFactory>
5053

0 commit comments

Comments
 (0)