Skip to content

Commit 69962ea

Browse files
vgromfeldmichael-hawker
authored andcommitted
Initial StackedNotificationsBehavior ported from CommunityToolkit/WindowsCommunityToolkit#4399
1 parent 1476e85 commit 69962ea

36 files changed

+1696
-0
lines changed

labs/StackedNotificationsBehavior/StackedNotificationsBehavior.sln

Lines changed: 311 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<!--
2+
WinUI 2 under UWP uses TargetFramework uap10.0.*
3+
WinUI 3 under WinAppSdk uses TargetFramework net6.0-windows10.*
4+
However, under Uno-powered platforms, both WinUI 2 and 3 can share the same TargetFramework.
5+
6+
MSBuild doesn't play nicely with this out of the box, so we've made it easy for you.
7+
8+
For .NET Standard packages, you can use the Nuget Package Manager in Visual Studio.
9+
For UWP / WinAppSDK / Uno packages, place the package references here.
10+
-->
11+
<Project>
12+
<!-- WinUI 2 / UWP -->
13+
<ItemGroup Condition="'$(IsUwp)' == 'true'">
14+
<!-- <PackageReference Include="Microsoft.Toolkit.Uwp.UI.Controls.Primitives" Version="7.1.2"/> -->
15+
</ItemGroup>
16+
17+
<!-- WinUI 2 / Uno -->
18+
<ItemGroup Condition="'$(IsUno)' == 'true' AND '$(WinUIMajorVersion)' == '2'">
19+
<!-- <PackageReference Include="Uno.Microsoft.Toolkit.Uwp.UI.Controls.Primitives" Version="7.1.11"/> -->
20+
</ItemGroup>
21+
22+
<!-- WinUI 3 / WinAppSdk -->
23+
<ItemGroup Condition="'$(IsWinAppSdk)' == 'true'">
24+
<!-- <PackageReference Include="CommunityToolkit.WinUI.UI.Controls.Primitives" Version="7.1.2"/> -->
25+
</ItemGroup>
26+
27+
<!-- WinUI 3 / Uno -->
28+
<ItemGroup Condition="'$(IsUno)' == 'true' AND '$(WinUIMajorVersion)' == '3'">
29+
<!-- <PackageReference Include="Uno.CommunityToolkit.WinUI.UI.Controls.Primitives" Version="7.1.100-dev.15.g12261e2626"/> -->
30+
</ItemGroup>
31+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<Project Sdk="MSBuild.Sdk.Extras/3.0.23">
2+
<!-- Labs Constants -->
3+
<Import Project="$(RepositoryDirectory)common\Labs.TargetFrameworks.props" />
4+
<Import Project="$(RepositoryDirectory)common\Labs.ProjectIdentifiers.props" />
5+
6+
<!-- Labs Platform Config -->
7+
<Import Project="$(RepositoryDirectory)common\Labs.Uno.props" />
8+
<Import Project="$(RepositoryDirectory)common\Labs.MultiTarget.props" />
9+
10+
<!-- Labs Project Config -->
11+
<Import Project="$(RepositoryDirectory)common\Labs.Sample.props" />
12+
13+
<PropertyGroup>
14+
<RootNamespace>StackedNotificationsBehaviorExperiment.Samples</RootNamespace>
15+
<AssemblyName>StackedNotificationsBehaviorExperiment.Samples</AssemblyName>
16+
</PropertyGroup>
17+
18+
<!-- Sample XAML Pages and Markdown files are automatically included, and don't need to be specified here. -->
19+
20+
<ItemGroup>
21+
<ProjectReference Include="..\..\src\CommunityToolkit.Labs.WinUI.StackedNotificationsBehavior.csproj" />
22+
</ItemGroup>
23+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
title: StackedNotificationsBehavior
3+
author: vgromfeld
4+
description: A behavior to add stacked notifications to a WinUI InfoBar control.
5+
keywords: StackedNotificationsBehavior, Control, Layout, InfoBar, Behavior
6+
dev_langs:
7+
- csharp
8+
category: Behaviors
9+
subcategory: StatusAndInfo
10+
---
11+
12+
# StackedNotificationsBehavior
13+
14+
For more information about this experiment see:
15+
16+
- Discussion: https://github.com/CommunityToolkit/WindowsCommunityToolkit/issues/4194
17+
- Issue: https://github.com/CommunityToolkit/Labs-Windows/issues/210
18+
19+
A behavior to add stacked notifications to a WinUI InfoBar control.
20+
21+
## Example
22+
23+
This initial example shows how to attach the behavior to an InfoBar and send it a message.
24+
25+
Clicking on the button multiple times will queue up multiple messages to be displayed one after another.
26+
27+
> [!Sample StackedNotificationsBehaviorCustomSample]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<!-- 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. -->
2+
<Page x:Class="StackedNotificationsBehaviorExperiment.Samples.StackedNotificationsBehaviorCustomSample"
3+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
4+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
6+
xmlns:interactivity="using:Microsoft.Xaml.Interactivity"
7+
xmlns:labs="using:CommunityToolkit.Labs.WinUI"
8+
xmlns:local="using:StackedNotificationsBehaviorExperiment.Samples"
9+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
10+
xmlns:muxc="using:Microsoft.UI.Xaml.Controls"
11+
mc:Ignorable="d">
12+
13+
<Grid>
14+
<Button HorizontalAlignment="Left"
15+
VerticalAlignment="Top"
16+
Click="Button_Click"
17+
Content="Send" />
18+
19+
<muxc:InfoBar MaxWidth="480"
20+
Margin="64"
21+
HorizontalAlignment="Right"
22+
VerticalAlignment="Bottom">
23+
<interactivity:Interaction.Behaviors>
24+
<labs:StackedNotificationsBehavior x:Name="NotificationQueue" />
25+
</interactivity:Interaction.Behaviors>
26+
</muxc:InfoBar>
27+
</Grid>
28+
</Page>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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+
namespace StackedNotificationsBehaviorExperiment.Samples;
6+
7+
/// <summary>
8+
/// An example sample page of a custom control inheriting from Panel.
9+
/// </summary>
10+
11+
[ToolkitSample(id: nameof(StackedNotificationsBehaviorCustomSample), "Stacked Notifications", description: $"A sample for showing how to create and use a {nameof(StackedNotificationsBehavior)} custom control.")]
12+
public sealed partial class StackedNotificationsBehaviorCustomSample : Page
13+
{
14+
public StackedNotificationsBehaviorCustomSample()
15+
{
16+
this.InitializeComponent();
17+
}
18+
19+
private void Button_Click(object sender, RoutedEventArgs e)
20+
{
21+
var notification = new Notification
22+
{
23+
Title = $"Notification {DateTimeOffset.Now}",
24+
Message = GetRandomText(),
25+
Severity = MUXC.InfoBarSeverity.Informational,
26+
};
27+
28+
NotificationQueue.Show(notification);
29+
}
30+
31+
private static string GetRandomText()
32+
{
33+
var random = new Random();
34+
var result = random.Next(1, 4);
35+
36+
switch (result)
37+
{
38+
case 1: return "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec sollicitudin bibendum enim at tincidunt. Praesent egestas ipsum ligula, nec tincidunt lacus semper non.";
39+
case 2: return "Pellentesque in risus eget leo rhoncus ultricies nec id ante.";
40+
case 3: default: return "Sed quis nisi quis nunc condimentum varius id consectetur metus. Duis mauris sapien, commodo eget erat ac, efficitur iaculis magna. Morbi eu velit nec massa pharetra cursus. Fusce non quam egestas leo finibus interdum eu ac massa. Quisque nec justo leo. Aenean scelerisque placerat ultrices. Sed accumsan lorem at arcu commodo tristique.";
41+
}
42+
}
43+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
3+
<Package
4+
xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10"
5+
xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest"
6+
xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10"
7+
IgnorableNamespaces="uap mp">
8+
9+
<Identity
10+
Name="Labs.StackedNotificationsBehavior.Uwp"
11+
Publisher="CN=CommunityToolkit"
12+
Version="1.0.0.0" />
13+
14+
<mp:PhoneIdentity PhoneProductId="D91EC294-02E8-4264-A71B-AEEFC69D8B1E" PhonePublisherId="00000000-0000-0000-0000-000000000000"/>
15+
16+
<Properties>
17+
<DisplayName>CommunityToolkit Labs: StackedNotificationsBehavior Samples (UWP)</DisplayName>
18+
<PublisherDisplayName>CommunityToolkit</PublisherDisplayName>
19+
<Logo>Assets\StoreLogo.png</Logo>
20+
</Properties>
21+
22+
<Dependencies>
23+
<TargetDeviceFamily Name="Windows.Universal" MinVersion="10.0.0.0" MaxVersionTested="10.0.0.0" />
24+
</Dependencies>
25+
26+
<Resources>
27+
<Resource Language="x-generate"/>
28+
</Resources>
29+
30+
<Applications>
31+
<Application Id="App"
32+
Executable="$targetnametoken$.exe"
33+
EntryPoint="CommunityToolkit.Labs.Shared.App">
34+
<uap:VisualElements
35+
DisplayName="CommunityToolkit Labs: StackedNotificationsBehavior Sample"
36+
Square150x150Logo="Assets\Square150x150Logo.png"
37+
Square44x44Logo="Assets\Square44x44Logo.png"
38+
Description="CommunityToolkit Labs Samples"
39+
BackgroundColor="transparent">
40+
<uap:DefaultTile Wide310x150Logo="Assets\Wide310x150Logo.png"/>
41+
<uap:SplashScreen Image="Assets\SplashScreen.png" />
42+
</uap:VisualElements>
43+
</Application>
44+
</Applications>
45+
46+
<Capabilities>
47+
<Capability Name="internetClient" />
48+
</Capabilities>
49+
</Package>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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.Reflection;
6+
using System.Runtime.CompilerServices;
7+
using System.Runtime.InteropServices;
8+
9+
// General Information about an assembly is controlled through the following
10+
// set of attributes. Change these attribute values to modify the information
11+
// associated with an assembly.
12+
[assembly: AssemblyTitle("CommunityToolkit.Labs.Uwp.Samples.StackedNotificationsBehavior")]
13+
[assembly: AssemblyDescription("")]
14+
[assembly: AssemblyConfiguration("")]
15+
[assembly: AssemblyCompany(".NET Foundation")]
16+
[assembly: AssemblyProduct("CommunityToolkit.Labs.Uwp.Samples.StackedNotificationsBehavior")]
17+
[assembly: AssemblyCopyright("Copyright © .NET Foundation 2022")]
18+
[assembly: AssemblyTrademark("")]
19+
[assembly: AssemblyCulture("")]
20+
21+
// Version information for an assembly consists of the following four values:
22+
//
23+
// Major Version
24+
// Minor Version
25+
// Build Number
26+
// Revision
27+
//
28+
// You can specify all the values or you can default the Build and Revision Numbers
29+
// by using the '*' as shown below:
30+
// [assembly: AssemblyVersion("1.0.*")]
31+
[assembly: AssemblyVersion("1.0.0.0")]
32+
[assembly: AssemblyFileVersion("1.0.0.0")]
33+
[assembly: ComVisible(false)]
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<!--
2+
This file contains Runtime Directives used by .NET Native. The defaults here are suitable for most
3+
developers. However, you can modify these parameters to modify the behavior of the .NET Native
4+
optimizer.
5+
6+
Runtime Directives are documented at https://go.microsoft.com/fwlink/?LinkID=391919
7+
8+
To fully enable reflection for App1.MyClass and all of its public/private members
9+
<Type Name="App1.MyClass" Dynamic="Required All"/>
10+
11+
To enable dynamic creation of the specific instantiation of AppClass<T> over System.Int32
12+
<TypeInstantiation Name="App1.AppClass" Arguments="System.Int32" Activate="Required Public" />
13+
14+
Using the Namespace directive to apply reflection policy to all the types in a particular namespace
15+
<Namespace Name="DataClasses.ViewModels" Serialize="All" />
16+
-->
17+
18+
<Directives xmlns="http://schemas.microsoft.com/netfx/2013/01/metadata">
19+
<Application>
20+
<!--
21+
An Assembly element with Name="*Application*" applies to all assemblies in
22+
the application package. The asterisks are not wildcards.
23+
-->
24+
<Assembly Name="*Application*" Dynamic="Required All" />
25+
26+
27+
<!-- Add your application specific runtime directives here. -->
28+
29+
30+
</Application>
31+
</Directives>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$([MSBuild]::GetPathOfFileAbove(directory.build.props))" Condition="Exists('$([MSBuild]::GetPathOfFileAbove(directory.build.props))')" />
4+
5+
<!-- Labs Constants -->
6+
<Import Project="$(RepositoryDirectory)common\Labs.TargetFrameworks.props" />
7+
<PropertyGroup>
8+
<IsDeployableHead>true</IsDeployableHead>
9+
<IsUno>false</IsUno>
10+
<IsWasm>false</IsWasm>
11+
<IsWasmHead>false</IsWasmHead>
12+
<IsWasmLib>false</IsWasmLib>
13+
<IsDroid>false</IsDroid>
14+
<IsMacOS>false</IsMacOS>
15+
<IsiOS>false</IsiOS>
16+
<IsUwp>true</IsUwp>
17+
<IsWinAppSdk>false</IsWinAppSdk>
18+
<IsWpf>false</IsWpf>
19+
<IsWpfHead>false</IsWpfHead>
20+
<IsWpfLib>false</IsWpfLib>
21+
<IsGtk>false</IsGtk>
22+
<IsGtkHead>false</IsGtkHead>
23+
<IsGtkLib>false</IsGtkLib>
24+
</PropertyGroup>
25+
<Import Project="$(RepositoryDirectory)common\Labs.ProjectIdentifiers.props" />
26+
27+
<!-- Labs Platform Config -->
28+
<Import Project="$(RepositoryDirectory)common\Labs.Head.Uwp.props" />
29+
30+
<!-- Labs Project Config -->
31+
<Import Project="$(RepositoryDirectory)common\Labs.Head.props" />
32+
33+
<PropertyGroup>
34+
<RootNamespace>StackedNotificationsBehaviorExperiment.Samples</RootNamespace>
35+
<AssemblyName>StackedNotificationsBehaviorExperiment.Samples.Uwp</AssemblyName>
36+
<ProjectGuid>{59EF2B08-F5FB-4182-8361-94B8475C4C6D}</ProjectGuid>
37+
</PropertyGroup>
38+
<ItemGroup>
39+
<Compile Include="Properties\AssemblyInfo.cs" />
40+
</ItemGroup>
41+
<ItemGroup>
42+
<Content Include="Properties\Default.rd.xml" />
43+
</ItemGroup>
44+
<ItemGroup>
45+
<AppxManifest Include="Package.appxmanifest">
46+
<SubType>Designer</SubType>
47+
</AppxManifest>
48+
</ItemGroup>
49+
<ItemGroup>
50+
<ProjectReference Include="..\..\src\CommunityToolkit.Labs.WinUI.StackedNotificationsBehavior.csproj">
51+
<Project>{78836C55-D21E-4724-935A-B08B0FF583F0}</Project>
52+
<Name>CommunityToolkit.Labs.WinUI.StackedNotificationsBehavior</Name>
53+
</ProjectReference>
54+
<ProjectReference Include="..\StackedNotificationsBehavior.Samples\StackedNotificationsBehavior.Samples.csproj">
55+
<Project>{261BDD36-FEEF-4260-AD9D-C1149EE5FE8E}</Project>
56+
<Name>StackedNotificationsBehavior.Sample</Name>
57+
</ProjectReference>
58+
</ItemGroup>
59+
<!-- Must be imported after any shared projects in non-sdk style projects -->
60+
<Import Project="$(MSBuildExtensionsPath)\Microsoft\WindowsXaml\v$(VisualStudioVersion)\Microsoft.Windows.UI.Xaml.CSharp.targets" />
61+
</Project>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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 CommunityToolkit.Labs.Shared;
6+
7+
namespace StackedNotificationsBehaviorExperiment.Samples.Wasm;
8+
9+
public class Program
10+
{
11+
private static App? _app;
12+
13+
static int Main(string[] args)
14+
{
15+
Application.Start(_ => _app = new App());
16+
17+
return 0;
18+
}
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"iisSettings": {
3+
"windowsAuthentication": false,
4+
"anonymousAuthentication": true,
5+
"iisExpress": {
6+
"applicationUrl": "http://localhost:59615/",
7+
"sslPort": 44370
8+
}
9+
},
10+
"profiles": {
11+
"IIS Express": {
12+
"commandName": "IISExpress",
13+
"launchBrowser": true,
14+
"environmentVariables": {
15+
"ASPNETCORE_ENVIRONMENT": "Development"
16+
}
17+
},
18+
"StackedNotificationsBehavior.Wasm": {
19+
"commandName": "Project",
20+
"launchBrowser": true,
21+
"environmentVariables": {
22+
"ASPNETCORE_ENVIRONMENT": "Development"
23+
},
24+
"applicationUrl": "https://localhost:5001;http://localhost:5000"
25+
}
26+
}
27+
}

0 commit comments

Comments
 (0)