Skip to content

Commit 9cac1b7

Browse files
committed
merge from master
2 parents b3b7ff5 + a21a44f commit 9cac1b7

27 files changed

+746
-332
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
<AppxBundlePlatforms>x86|x64|arm|arm64</AppxBundlePlatforms>
2222
<Win32Resource>MiddleClickScrolling-CursorType.res</Win32Resource>
2323
<AppxPackageSigningEnabled>false</AppxPackageSigningEnabled>
24+
<LangVersion>8.0</LangVersion>
2425
</PropertyGroup>
2526
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
2627
<DebugSymbols>true</DebugSymbols>
@@ -516,6 +517,9 @@
516517
</Content>
517518
<Content Include="SamplePages\Weibo Service\WeiboCode.bind" />
518519
<Compile Include="Common\TextBlockHyperlinkBehavior.cs" />
520+
<Compile Include="SamplePages\EnumValuesExtension\EnumValuesExtensionPage.xaml.cs">
521+
<DependentUpon>EnumValuesExtensionPage.xaml</DependentUpon>
522+
</Compile>
519523
<Compile Include="SamplePages\TilesBrush\TilesBrushPage.xaml.cs">
520524
<DependentUpon>TilesBrushPage.xaml</DependentUpon>
521525
</Compile>
@@ -617,6 +621,8 @@
617621
<Content Include="SamplePages\Triggers\UserHandPreferenceStateTrigger.bind" />
618622
<Content Include="SamplePages\Triggers\UserInteractionModeStateTrigger.bind" />
619623
<Content Include="SamplePages\StaggeredLayout\StaggeredLayout.bind" />
624+
<Content Include="SamplePages\EnumValuesExtension\EnumValuesExtensionXaml.bind" />
625+
<Content Include="SamplePages\EnumValuesExtension\EnumValuesExtensionCode.bind" />
620626
</ItemGroup>
621627
<ItemGroup>
622628
<Compile Include="App.xaml.cs">
@@ -995,6 +1001,10 @@
9951001
<SubType>Designer</SubType>
9961002
<Generator>MSBuild:Compile</Generator>
9971003
</Page>
1004+
<Page Include="SamplePages\EnumValuesExtension\EnumValuesExtensionPage.xaml">
1005+
<Generator>MSBuild:Compile</Generator>
1006+
<SubType>Designer</SubType>
1007+
</Page>
9981008
<Page Include="SamplePages\TilesBrush\TilesBrushPage.xaml">
9991009
<Generator>MSBuild:Compile</Generator>
10001010
<SubType>Designer</SubType>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Let's declare a sample enum
2+
public enum Animal
3+
{
4+
Cat,
5+
Dog,
6+
Bunny,
7+
Parrot,
8+
Squirrel
9+
}
10+
11+
// We can use a converter to get other values from our enum
12+
public sealed class AnimalToColorConverter : IValueConverter
13+
{
14+
public object Convert(object value, Type targetType, object parameter, string language)
15+
{
16+
return (Animal)value switch
17+
{
18+
Animal.Cat => Colors.Coral,
19+
Animal.Dog => Colors.Gray,
20+
Animal.Bunny => Colors.Green,
21+
Animal.Parrot => Colors.YellowGreen,
22+
Animal.Squirrel => Colors.SaddleBrown,
23+
_ => throw new ArgumentException("Invalid value", nameof(value))
24+
};
25+
}
26+
27+
public object ConvertBack(object value, Type targetType, object parameter, string language)
28+
{
29+
throw new NotImplementedException();
30+
}
31+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<Page x:Class="Microsoft.Toolkit.Uwp.SampleApp.SamplePages.EnumValuesExtensionPage"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
5+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
6+
xmlns:ex="using:Microsoft.Toolkit.Uwp.UI.Extensions"
7+
xmlns:enums="using:Microsoft.Toolkit.Uwp.SampleApp.Enums"
8+
xmlns:converters="using:Microsoft.Toolkit.Uwp.SampleApp.Converters"
9+
mc:Ignorable="d">
10+
<Page.Resources>
11+
<enums:Animal x:Key="MyAnimal">Cat</enums:Animal>
12+
<converters:AnimalToColorConverter x:Key="AnimalToColorConverter"/>
13+
</Page.Resources>
14+
<Grid>
15+
<StackPanel Spacing="8">
16+
<ComboBox ItemsSource="{ex:EnumValues Type=enums:Animal}"/>
17+
<ComboBox ItemsSource="{ex:EnumValues Type=enums:Animal}"
18+
SelectedIndex="0">
19+
<ComboBox.ItemTemplate>
20+
<DataTemplate>
21+
<StackPanel Orientation="Horizontal">
22+
<TextBlock Text="{Binding}"/>
23+
<Rectangle Height="16"
24+
Width="16">
25+
<Rectangle.Fill>
26+
<SolidColorBrush Color="{Binding Converter={StaticResource AnimalToColorConverter}}"/>
27+
</Rectangle.Fill>
28+
</Rectangle>
29+
</StackPanel>
30+
</DataTemplate>
31+
</ComboBox.ItemTemplate>
32+
</ComboBox>
33+
</StackPanel>
34+
</Grid>
35+
</Page>
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using System;
6+
using Windows.UI;
7+
using Microsoft.Toolkit.Uwp.UI.Extensions;
8+
using Windows.UI.Xaml;
9+
using Windows.UI.Xaml.Data;
10+
using Microsoft.Toolkit.Uwp.SampleApp.Enums;
11+
12+
namespace Microsoft.Toolkit.Uwp.SampleApp.SamplePages
13+
{
14+
/// <summary>
15+
/// A page that shows how to use the <see cref="EnumValuesExtension"/> type.
16+
/// </summary>
17+
public sealed partial class EnumValuesExtensionPage : IXamlRenderListener
18+
{
19+
/// <summary>
20+
/// Initializes a new instance of the <see cref="EnumValuesExtensionPage"/> class.
21+
/// </summary>
22+
public EnumValuesExtensionPage()
23+
{
24+
InitializeComponent();
25+
}
26+
27+
public void OnXamlRendered(FrameworkElement control)
28+
{
29+
}
30+
}
31+
}
32+
33+
#pragma warning disable SA1403 // File may only contain a single namespace
34+
namespace Microsoft.Toolkit.Uwp.SampleApp.Enums
35+
{
36+
public enum Animal
37+
{
38+
Cat,
39+
Dog,
40+
Bunny,
41+
Parrot,
42+
Squirrel
43+
}
44+
}
45+
46+
namespace Microsoft.Toolkit.Uwp.SampleApp.Converters
47+
{
48+
public sealed class AnimalToColorConverter : IValueConverter
49+
{
50+
public object Convert(object value, Type targetType, object parameter, string language)
51+
{
52+
return (Animal)value switch
53+
{
54+
Animal.Cat => Colors.Coral,
55+
Animal.Dog => Colors.Gray,
56+
Animal.Bunny => Colors.Green,
57+
Animal.Parrot => Colors.YellowGreen,
58+
Animal.Squirrel => Colors.SaddleBrown,
59+
_ => throw new ArgumentException("Invalid value", nameof(value))
60+
};
61+
}
62+
63+
public object ConvertBack(object value, Type targetType, object parameter, string language)
64+
{
65+
throw new NotImplementedException();
66+
}
67+
}
68+
}
69+
70+
#pragma warning restore SA1403
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<Page
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:local="using:Microsoft.Toolkit.Uwp.SampleApp.SamplePages.EnumValuesExtensionPage"
5+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
6+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
7+
xmlns:ex="using:Microsoft.Toolkit.Uwp.UI.Extensions"
8+
xmlns:enums="using:Microsoft.Toolkit.Uwp.SampleApp.Enums"
9+
xmlns:converters="using:Microsoft.Toolkit.Uwp.SampleApp.Converters"
10+
mc:Ignorable="d">
11+
<Page.Resources>
12+
<converters:AnimalToColorConverter x:Key="AnimalToColorConverter"/>
13+
</Page.Resources>
14+
<Grid>
15+
<StackPanel Spacing="8"
16+
HorizontalAlignment="Center"
17+
VerticalAlignment="Center">
18+
19+
<!--Simple selector using the default template. Each item will
20+
simply be displayed as the corresponding enum value name.-->
21+
<TextBlock Text="Select an animal:"/>
22+
<ComboBox ItemsSource="{ex:EnumValues Type=enums:Animal}"
23+
SelectedIndex="0"/>
24+
25+
<!--We can also use a custom template and some converters.-->
26+
<TextBlock Margin="0,12,0,0"
27+
Text="Pick another animal:"/>
28+
<ComboBox ItemsSource="{ex:EnumValues Type=enums:Animal}"
29+
SelectedIndex="0">
30+
<ComboBox.ItemTemplate>
31+
<DataTemplate>
32+
<Grid Width="80">
33+
<TextBlock Text="{Binding}"/>
34+
<Rectangle Height="16"
35+
Width="16"
36+
HorizontalAlignment="Right">
37+
<Rectangle.Fill>
38+
<SolidColorBrush Color="{Binding Converter={StaticResource AnimalToColorConverter}}"/>
39+
</Rectangle.Fill>
40+
</Rectangle>
41+
</Grid>
42+
</DataTemplate>
43+
</ComboBox.ItemTemplate>
44+
</ComboBox>
45+
</StackPanel>
46+
</Grid>
47+
</Page>

Microsoft.Toolkit.Uwp.SampleApp/SamplePages/InAppNotification/InAppNotificationCode.bind

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,21 +46,29 @@ if (isTemplatePresent && inAppNotificationWithButtonsTemplate is DataTemplate)
4646
ExampleInAppNotification.Show(inAppNotificationWithButtonsTemplate as DataTemplate);
4747
}
4848

49+
// Show notification using an object
50+
<controls:InAppNotification
51+
x:Name="ExampleInAppNotification"
52+
ContentTemplate="{StaticResource MyNotificationDataTemplate}" />
53+
54+
var notificationData = new MyNotificationData("Title", "Message");
55+
ExampleInAppNotification.Show(notificationData, duration: 2000);
56+
4957
// Dismiss notification
5058
ExampleInAppNotification.Dismiss();
5159

5260
// ## C# - Handle button events
5361

5462
private void YesButton_Click(object sender, RoutedEventArgs e)
5563
{
56-
// TODO : Do something when user accepted
64+
// TODO : Do something when user accepted
5765

5866
ExampleInAppNotification.Dismiss();
5967
}
6068

6169
private void NoButton_Click(object sender, RoutedEventArgs e)
6270
{
63-
// TODO : Do something when user refused
71+
// TODO : Do something when user refused
6472

6573
ExampleInAppNotification.Dismiss();
6674
}

Microsoft.Toolkit.Uwp.SampleApp/SamplePages/InAppNotification/InAppNotificationPage.xaml.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5-
using System;
6-
using System.Windows.Input;
75
using Microsoft.Toolkit.Uwp.UI.Controls;
86
using Microsoft.Toolkit.Uwp.UI.Extensions;
7+
using System;
8+
using System.Collections.Generic;
9+
using System.Windows.Input;
910
using Windows.UI.Xaml;
1011
using Windows.UI.Xaml.Controls;
1112

@@ -57,6 +58,15 @@ private void Load()
5758
_exampleInAppNotification?.Show(GetRandomText(), NotificationDuration);
5859
});
5960

61+
SampleController.Current.RegisterNewCommand("Show notification with object", (sender, args) =>
62+
{
63+
_exampleVSCodeInAppNotification?.Dismiss();
64+
SetDefaultControlTemplate();
65+
66+
var random = new Random();
67+
_exampleInAppNotification?.Show(new KeyValuePair<int, string>(random.Next(1, 10), GetRandomText()), NotificationDuration);
68+
});
69+
6070
SampleController.Current.RegisterNewCommand("Show notification with buttons (without DataTemplate)", (sender, args) =>
6171
{
6272
_exampleVSCodeInAppNotification?.Dismiss();

Microsoft.Toolkit.Uwp.SampleApp/SamplePages/InAppNotification/InAppNotificationXaml.bind

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,8 @@
153153
<ColumnDefinition Width="Auto" />
154154
</Grid.ColumnDefinitions>
155155

156-
<ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
156+
<ContentPresenter x:Name="PART_Presenter"
157+
HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
157158
HorizontalContentAlignment="Stretch"
158159
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
159160
VerticalContentAlignment="Center"
@@ -333,7 +334,8 @@
333334
<ColumnDefinition Width="Auto" />
334335
</Grid.ColumnDefinitions>
335336

336-
<ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
337+
<ContentPresenter x:Name="PART_Presenter"
338+
HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
337339
HorizontalContentAlignment="Stretch"
338340
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
339341
VerticalContentAlignment="Center"
@@ -376,7 +378,17 @@
376378
AnimationDuration="@[AnimationDuration:TimeSpan:100:0-5000]"
377379
VerticalOffset="@[VerticalOffset:DoubleSlider:100.0:-200.0-200.0]"
378380
HorizontalOffset="@[HorizontalOffset:DoubleSlider:0.0:-200.0-200.0]"
379-
StackMode="@[StackMode:Enum:StackMode.Replace]" />
381+
StackMode="@[StackMode:Enum:StackMode.Replace]">
382+
<controls:InAppNotification.ContentTemplate>
383+
<DataTemplate>
384+
<StackPanel>
385+
<TextBlock Text="{Binding Value}" Margin="0,0,0,8" />
386+
<TextBlock Text="{Binding Key}" Style="{ThemeResource CaptionTextBlockStyle}" Opacity="0.8" />
387+
</StackPanel>
388+
</DataTemplate>
389+
</controls:InAppNotification.ContentTemplate>
390+
</controls:InAppNotification>
391+
380392

381393
<controls:InAppNotification x:Name="ExampleCustomInAppNotification"
382394
Style="{StaticResource MSEdgeNotificationTemplate_NoDismissButton}"

Microsoft.Toolkit.Uwp.SampleApp/SamplePages/samples.json

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1266,15 +1266,23 @@
12661266
"XamlCodeFile": "OnDeviceXaml.bind",
12671267
"DocumentationUrl": "https://raw.githubusercontent.com/MicrosoftDocs/WindowsCommunityToolkitDocs/master/docs/extensions/OnDeviceMarkup.md"
12681268
},
1269-
{
1270-
"Name": "IconExtensions",
1271-
"Type": "IconExtensionsPage",
1272-
"About": "Markup extensions to easily create various types of icons.",
1273-
"CodeUrl": "https://github.com/windows-toolkit/WindowsCommunityToolkit/tree/master/Microsoft.Toolkit.Uwp.UI/Extensions/Markup/FontIconExtension",
1274-
"XamlCodeFile": "IconExtensionsXaml.bind",
1275-
"Icon": "/Assets/Helpers.png",
1276-
"DocumentationUrl": "https://raw.githubusercontent.com/MicrosoftDocs/WindowsCommunityToolkitDocs/master/docs/extensions/IconExtensions.md"
1277-
}
1269+
{
1270+
"Name": "IconExtensions",
1271+
"Type": "IconExtensionsPage",
1272+
"About": "Markup extensions to easily create various types of icons.",
1273+
"CodeUrl": "https://github.com/windows-toolkit/WindowsCommunityToolkit/tree/master/Microsoft.Toolkit.Uwp.UI/Extensions/Markup/FontIconExtension",
1274+
"XamlCodeFile": "IconExtensionsXaml.bind",
1275+
"Icon": "/Assets/Helpers.png",
1276+
"DocumentationUrl": "https://raw.githubusercontent.com/MicrosoftDocs/WindowsCommunityToolkitDocs/master/docs/extensions/IconExtensions.md"
1277+
},
1278+
{
1279+
"Name": "EnumValuesExtension",
1280+
"Type": "EnumValuesExtensionPage",
1281+
"About": "The EnumValuesExtension markup extension allows you to easily retrieve a collection of all values from an enum type.",
1282+
"Icon": "/Assets/Helpers.png",
1283+
"XamlCodeFile": "EnumValuesExtensionXaml.bind",
1284+
"CodeFile": "EnumValuesExtensionCode.bind"
1285+
}
12781286
]
12791287
},
12801288
{

Microsoft.Toolkit.Uwp.UI.Controls/InAppNotification/InAppNotification.Constants.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,10 @@ public partial class InAppNotification
2828
/// Key of the UI Element that dismiss the control
2929
/// </summary>
3030
private const string DismissButtonPart = "PART_DismissButton";
31+
32+
/// <summary>
33+
/// Key of the UI Element that will display the notification content.
34+
/// </summary>
35+
private const string ContentPresenterPart = "PART_Presenter";
3136
}
3237
}

0 commit comments

Comments
 (0)