-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial StackedNotificationsBehavior ported from CommunityToolkit/Win…
- Loading branch information
1 parent
3b8a14c
commit c865d54
Showing
36 changed files
with
1,705 additions
and
0 deletions.
There are no files selected for viewing
311 changes: 311 additions & 0 deletions
311
labs/StackedNotificationsBehavior/StackedNotificationsBehavior.sln
Large diffs are not rendered by default.
Oops, something went wrong.
31 changes: 31 additions & 0 deletions
31
...ckedNotificationsBehavior/samples/StackedNotificationsBehavior.Samples/Dependencies.props
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<!-- | ||
WinUI 2 under UWP uses TargetFramework uap10.0.* | ||
WinUI 3 under WinAppSdk uses TargetFramework net6.0-windows10.* | ||
However, under Uno-powered platforms, both WinUI 2 and 3 can share the same TargetFramework. | ||
MSBuild doesn't play nicely with this out of the box, so we've made it easy for you. | ||
For .NET Standard packages, you can use the Nuget Package Manager in Visual Studio. | ||
For UWP / WinAppSDK / Uno packages, place the package references here. | ||
--> | ||
<Project> | ||
<!-- WinUI 2 / UWP --> | ||
<ItemGroup Condition="'$(IsUwp)' == 'true'"> | ||
<!-- <PackageReference Include="Microsoft.Toolkit.Uwp.UI.Controls.Primitives" Version="7.1.2"/> --> | ||
</ItemGroup> | ||
|
||
<!-- WinUI 2 / Uno --> | ||
<ItemGroup Condition="'$(IsUno)' == 'true' AND '$(WinUIMajorVersion)' == '2'"> | ||
<!-- <PackageReference Include="Uno.Microsoft.Toolkit.Uwp.UI.Controls.Primitives" Version="7.1.11"/> --> | ||
</ItemGroup> | ||
|
||
<!-- WinUI 3 / WinAppSdk --> | ||
<ItemGroup Condition="'$(IsWinAppSdk)' == 'true'"> | ||
<!-- <PackageReference Include="CommunityToolkit.WinUI.UI.Controls.Primitives" Version="7.1.2"/> --> | ||
</ItemGroup> | ||
|
||
<!-- WinUI 3 / Uno --> | ||
<ItemGroup Condition="'$(IsUno)' == 'true' AND '$(WinUIMajorVersion)' == '3'"> | ||
<!-- <PackageReference Include="Uno.CommunityToolkit.WinUI.UI.Controls.Primitives" Version="7.1.100-dev.15.g12261e2626"/> --> | ||
</ItemGroup> | ||
</Project> |
23 changes: 23 additions & 0 deletions
23
.../samples/StackedNotificationsBehavior.Samples/StackedNotificationsBehavior.Samples.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<Project Sdk="MSBuild.Sdk.Extras/3.0.23"> | ||
<!-- Labs Constants --> | ||
<Import Project="$(RepositoryDirectory)common\Labs.TargetFrameworks.props" /> | ||
<Import Project="$(RepositoryDirectory)common\Labs.ProjectIdentifiers.props" /> | ||
|
||
<!-- Labs Platform Config --> | ||
<Import Project="$(RepositoryDirectory)common\Labs.Uno.props" /> | ||
<Import Project="$(RepositoryDirectory)common\Labs.MultiTarget.props" /> | ||
|
||
<!-- Labs Project Config --> | ||
<Import Project="$(RepositoryDirectory)common\Labs.Sample.props" /> | ||
|
||
<PropertyGroup> | ||
<RootNamespace>StackedNotificationsBehaviorExperiment.Samples</RootNamespace> | ||
<AssemblyName>StackedNotificationsBehaviorExperiment.Samples</AssemblyName> | ||
</PropertyGroup> | ||
|
||
<!-- Sample XAML Pages and Markdown files are automatically included, and don't need to be specified here. --> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\CommunityToolkit.Labs.WinUI.StackedNotificationsBehavior.csproj" /> | ||
</ItemGroup> | ||
</Project> |
27 changes: 27 additions & 0 deletions
27
...or/samples/StackedNotificationsBehavior.Samples/StackedNotificationsBehavior.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
--- | ||
title: StackedNotificationsBehavior | ||
author: vgromfeld | ||
description: A behavior to add stacked notifications to a WinUI InfoBar control. | ||
keywords: StackedNotificationsBehavior, Control, Layout, InfoBar, Behavior | ||
dev_langs: | ||
- csharp | ||
category: Behaviors | ||
subcategory: StatusAndInfo | ||
--- | ||
|
||
# StackedNotificationsBehavior | ||
|
||
For more information about this experiment see: | ||
|
||
- Discussion: https://github.com/CommunityToolkit/WindowsCommunityToolkit/issues/4194 | ||
- Issue: https://github.com/CommunityToolkit/Labs-Windows/issues/210 | ||
|
||
A behavior to add stacked notifications to a WinUI InfoBar control. | ||
|
||
## Example | ||
|
||
This initial example shows how to attach the behavior to an InfoBar and send it a message. | ||
|
||
Clicking on the button multiple times will queue up multiple messages to be displayed one after another. | ||
|
||
> [!Sample StackedNotificationsBehaviorCustomSample] |
28 changes: 28 additions & 0 deletions
28
...amples/StackedNotificationsBehavior.Samples/StackedNotificationsBehaviorCustomSample.xaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<!-- 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. --> | ||
<Page x:Class="StackedNotificationsBehaviorExperiment.Samples.StackedNotificationsBehaviorCustomSample" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:interactivity="using:Microsoft.Xaml.Interactivity" | ||
xmlns:labs="using:CommunityToolkit.Labs.WinUI" | ||
xmlns:local="using:StackedNotificationsBehaviorExperiment.Samples" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
xmlns:muxc="using:Microsoft.UI.Xaml.Controls" | ||
mc:Ignorable="d"> | ||
|
||
<Grid> | ||
<Button HorizontalAlignment="Left" | ||
VerticalAlignment="Top" | ||
Click="Button_Click" | ||
Content="Send" /> | ||
|
||
<muxc:InfoBar MaxWidth="480" | ||
Margin="64" | ||
HorizontalAlignment="Right" | ||
VerticalAlignment="Bottom"> | ||
<interactivity:Interaction.Behaviors> | ||
<labs:StackedNotificationsBehavior x:Name="NotificationQueue" /> | ||
</interactivity:Interaction.Behaviors> | ||
</muxc:InfoBar> | ||
</Grid> | ||
</Page> |
43 changes: 43 additions & 0 deletions
43
...les/StackedNotificationsBehavior.Samples/StackedNotificationsBehaviorCustomSample.xaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// 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. | ||
|
||
namespace StackedNotificationsBehaviorExperiment.Samples; | ||
|
||
/// <summary> | ||
/// An example sample page of a custom control inheriting from Panel. | ||
/// </summary> | ||
|
||
[ToolkitSample(id: nameof(StackedNotificationsBehaviorCustomSample), "Stacked Notifications", description: $"A sample for showing how to create and use a {nameof(StackedNotificationsBehavior)} custom control.")] | ||
public sealed partial class StackedNotificationsBehaviorCustomSample : Page | ||
{ | ||
public StackedNotificationsBehaviorCustomSample() | ||
{ | ||
this.InitializeComponent(); | ||
} | ||
|
||
private void Button_Click(object sender, RoutedEventArgs e) | ||
{ | ||
var notification = new Notification | ||
{ | ||
Title = $"Notification {DateTimeOffset.Now}", | ||
Message = GetRandomText(), | ||
Severity = MUXC.InfoBarSeverity.Informational, | ||
}; | ||
|
||
NotificationQueue.Show(notification); | ||
} | ||
|
||
private static string GetRandomText() | ||
{ | ||
var random = new Random(); | ||
var result = random.Next(1, 4); | ||
|
||
switch (result) | ||
{ | ||
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."; | ||
case 2: return "Pellentesque in risus eget leo rhoncus ultricies nec id ante."; | ||
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."; | ||
} | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
...tackedNotificationsBehavior/samples/StackedNotificationsBehavior.Uwp/Package.appxmanifest
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
|
||
<Package | ||
xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10" | ||
xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest" | ||
xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10" | ||
IgnorableNamespaces="uap mp"> | ||
|
||
<Identity | ||
Name="Labs.StackedNotificationsBehavior.Uwp" | ||
Publisher="CN=CommunityToolkit" | ||
Version="1.0.0.0" /> | ||
|
||
<mp:PhoneIdentity PhoneProductId="D91EC294-02E8-4264-A71B-AEEFC69D8B1E" PhonePublisherId="00000000-0000-0000-0000-000000000000"/> | ||
|
||
<Properties> | ||
<DisplayName>CommunityToolkit Labs: StackedNotificationsBehavior Samples (UWP)</DisplayName> | ||
<PublisherDisplayName>CommunityToolkit</PublisherDisplayName> | ||
<Logo>Assets\StoreLogo.png</Logo> | ||
</Properties> | ||
|
||
<Dependencies> | ||
<TargetDeviceFamily Name="Windows.Universal" MinVersion="10.0.0.0" MaxVersionTested="10.0.0.0" /> | ||
</Dependencies> | ||
|
||
<Resources> | ||
<Resource Language="x-generate"/> | ||
</Resources> | ||
|
||
<Applications> | ||
<Application Id="App" | ||
Executable="$targetnametoken$.exe" | ||
EntryPoint="CommunityToolkit.Labs.Shared.App"> | ||
<uap:VisualElements | ||
DisplayName="CommunityToolkit Labs: StackedNotificationsBehavior Sample" | ||
Square150x150Logo="Assets\Square150x150Logo.png" | ||
Square44x44Logo="Assets\Square44x44Logo.png" | ||
Description="CommunityToolkit Labs Samples" | ||
BackgroundColor="transparent"> | ||
<uap:DefaultTile Wide310x150Logo="Assets\Wide310x150Logo.png"/> | ||
<uap:SplashScreen Image="Assets\SplashScreen.png" /> | ||
</uap:VisualElements> | ||
</Application> | ||
</Applications> | ||
|
||
<Capabilities> | ||
<Capability Name="internetClient" /> | ||
</Capabilities> | ||
</Package> |
33 changes: 33 additions & 0 deletions
33
...NotificationsBehavior/samples/StackedNotificationsBehavior.Uwp/Properties/AssemblyInfo.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// 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. | ||
|
||
using System.Reflection; | ||
using System.Runtime.CompilerServices; | ||
using System.Runtime.InteropServices; | ||
|
||
// General Information about an assembly is controlled through the following | ||
// set of attributes. Change these attribute values to modify the information | ||
// associated with an assembly. | ||
[assembly: AssemblyTitle("CommunityToolkit.Labs.Uwp.Samples.StackedNotificationsBehavior")] | ||
[assembly: AssemblyDescription("")] | ||
[assembly: AssemblyConfiguration("")] | ||
[assembly: AssemblyCompany(".NET Foundation")] | ||
[assembly: AssemblyProduct("CommunityToolkit.Labs.Uwp.Samples.StackedNotificationsBehavior")] | ||
[assembly: AssemblyCopyright("Copyright © .NET Foundation 2022")] | ||
[assembly: AssemblyTrademark("")] | ||
[assembly: AssemblyCulture("")] | ||
|
||
// Version information for an assembly consists of the following four values: | ||
// | ||
// Major Version | ||
// Minor Version | ||
// Build Number | ||
// Revision | ||
// | ||
// You can specify all the values or you can default the Build and Revision Numbers | ||
// by using the '*' as shown below: | ||
// [assembly: AssemblyVersion("1.0.*")] | ||
[assembly: AssemblyVersion("1.0.0.0")] | ||
[assembly: AssemblyFileVersion("1.0.0.0")] | ||
[assembly: ComVisible(false)] |
31 changes: 31 additions & 0 deletions
31
...dNotificationsBehavior/samples/StackedNotificationsBehavior.Uwp/Properties/Default.rd.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<!-- | ||
This file contains Runtime Directives used by .NET Native. The defaults here are suitable for most | ||
developers. However, you can modify these parameters to modify the behavior of the .NET Native | ||
optimizer. | ||
Runtime Directives are documented at https://go.microsoft.com/fwlink/?LinkID=391919 | ||
To fully enable reflection for App1.MyClass and all of its public/private members | ||
<Type Name="App1.MyClass" Dynamic="Required All"/> | ||
To enable dynamic creation of the specific instantiation of AppClass<T> over System.Int32 | ||
<TypeInstantiation Name="App1.AppClass" Arguments="System.Int32" Activate="Required Public" /> | ||
Using the Namespace directive to apply reflection policy to all the types in a particular namespace | ||
<Namespace Name="DataClasses.ViewModels" Serialize="All" /> | ||
--> | ||
|
||
<Directives xmlns="http://schemas.microsoft.com/netfx/2013/01/metadata"> | ||
<Application> | ||
<!-- | ||
An Assembly element with Name="*Application*" applies to all assemblies in | ||
the application package. The asterisks are not wildcards. | ||
--> | ||
<Assembly Name="*Application*" Dynamic="Required All" /> | ||
|
||
|
||
<!-- Add your application specific runtime directives here. --> | ||
|
||
|
||
</Application> | ||
</Directives> |
61 changes: 61 additions & 0 deletions
61
...Behavior/samples/StackedNotificationsBehavior.Uwp/StackedNotificationsBehavior.Uwp.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<Import Project="$([MSBuild]::GetPathOfFileAbove(directory.build.props))" Condition="Exists('$([MSBuild]::GetPathOfFileAbove(directory.build.props))')" /> | ||
|
||
<!-- Labs Constants --> | ||
<Import Project="$(RepositoryDirectory)common\Labs.TargetFrameworks.props" /> | ||
<PropertyGroup> | ||
<IsDeployableHead>true</IsDeployableHead> | ||
<IsUno>false</IsUno> | ||
<IsWasm>false</IsWasm> | ||
<IsWasmHead>false</IsWasmHead> | ||
<IsWasmLib>false</IsWasmLib> | ||
<IsDroid>false</IsDroid> | ||
<IsMacOS>false</IsMacOS> | ||
<IsiOS>false</IsiOS> | ||
<IsUwp>true</IsUwp> | ||
<IsWinAppSdk>false</IsWinAppSdk> | ||
<IsWpf>false</IsWpf> | ||
<IsWpfHead>false</IsWpfHead> | ||
<IsWpfLib>false</IsWpfLib> | ||
<IsGtk>false</IsGtk> | ||
<IsGtkHead>false</IsGtkHead> | ||
<IsGtkLib>false</IsGtkLib> | ||
</PropertyGroup> | ||
<Import Project="$(RepositoryDirectory)common\Labs.ProjectIdentifiers.props" /> | ||
|
||
<!-- Labs Platform Config --> | ||
<Import Project="$(RepositoryDirectory)common\Labs.Head.Uwp.props" /> | ||
|
||
<!-- Labs Project Config --> | ||
<Import Project="$(RepositoryDirectory)common\Labs.Head.props" /> | ||
|
||
<PropertyGroup> | ||
<RootNamespace>StackedNotificationsBehaviorExperiment.Samples</RootNamespace> | ||
<AssemblyName>StackedNotificationsBehaviorExperiment.Samples.Uwp</AssemblyName> | ||
<ProjectGuid>{59EF2B08-F5FB-4182-8361-94B8475C4C6D}</ProjectGuid> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Compile Include="Properties\AssemblyInfo.cs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Content Include="Properties\Default.rd.xml" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<AppxManifest Include="Package.appxmanifest"> | ||
<SubType>Designer</SubType> | ||
</AppxManifest> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\CommunityToolkit.Labs.WinUI.StackedNotificationsBehavior.csproj"> | ||
<Project>{78836C55-D21E-4724-935A-B08B0FF583F0}</Project> | ||
<Name>CommunityToolkit.Labs.WinUI.StackedNotificationsBehavior</Name> | ||
</ProjectReference> | ||
<ProjectReference Include="..\StackedNotificationsBehavior.Samples\StackedNotificationsBehavior.Samples.csproj"> | ||
<Project>{261BDD36-FEEF-4260-AD9D-C1149EE5FE8E}</Project> | ||
<Name>StackedNotificationsBehavior.Sample</Name> | ||
</ProjectReference> | ||
</ItemGroup> | ||
<!-- Must be imported after any shared projects in non-sdk style projects --> | ||
<Import Project="$(MSBuildExtensionsPath)\Microsoft\WindowsXaml\v$(VisualStudioVersion)\Microsoft.Windows.UI.Xaml.CSharp.targets" /> | ||
</Project> |
19 changes: 19 additions & 0 deletions
19
labs/StackedNotificationsBehavior/samples/StackedNotificationsBehavior.Wasm/Program.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// 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. | ||
|
||
using CommunityToolkit.Labs.Shared; | ||
|
||
namespace StackedNotificationsBehaviorExperiment.Samples.Wasm; | ||
|
||
public class Program | ||
{ | ||
private static App? _app; | ||
|
||
static int Main(string[] args) | ||
{ | ||
Application.Start(_ => _app = new App()); | ||
|
||
return 0; | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...icationsBehavior/samples/StackedNotificationsBehavior.Wasm/Properties/launchSettings.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
"iisSettings": { | ||
"windowsAuthentication": false, | ||
"anonymousAuthentication": true, | ||
"iisExpress": { | ||
"applicationUrl": "http://localhost:59615/", | ||
"sslPort": 44370 | ||
} | ||
}, | ||
"profiles": { | ||
"IIS Express": { | ||
"commandName": "IISExpress", | ||
"launchBrowser": true, | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
} | ||
}, | ||
"StackedNotificationsBehavior.Wasm": { | ||
"commandName": "Project", | ||
"launchBrowser": true, | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
}, | ||
"applicationUrl": "https://localhost:5001;http://localhost:5000" | ||
} | ||
} | ||
} |
Oops, something went wrong.