├── Documentation
├── Toast1.PNG
├── Toast2.PNG
├── Toast3.PNG
├── Toast4.PNG
└── Toast5.PNG
├── PeanutButter.Toasts
├── Icons
│ └── CrossWhite.png
├── Properties
│ ├── Settings.settings
│ ├── Settings.Designer.cs
│ ├── AssemblyInfo.cs
│ ├── Resources.Designer.cs
│ └── Resources.resx
├── ToastNotificationHost.xaml
├── Toast.cs
├── ToastNotificationHost.xaml.cs
├── Toaster.cs
├── IToaster.cs
├── PeanutButter.Toast.csproj
├── ToastNotification.cs
└── Themes
│ └── Generic.xaml
├── PeanutButter.Toast.Demo
├── App.config
├── Properties
│ ├── Settings.settings
│ ├── Settings.Designer.cs
│ ├── AssemblyInfo.cs
│ ├── Resources.Designer.cs
│ └── Resources.resx
├── App.xaml.cs
├── App.xaml
├── MainWindow.xaml.cs
├── MainWindow.xaml
└── PeanutButter.Toast.Demo.csproj
├── Properties
└── AssemblyInfo.cs
├── PeanutButter.Toast.sln
├── gitignore
└── README.md
/Documentation/Toast1.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mike-eason/WPF_ToastNotifications/HEAD/Documentation/Toast1.PNG
--------------------------------------------------------------------------------
/Documentation/Toast2.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mike-eason/WPF_ToastNotifications/HEAD/Documentation/Toast2.PNG
--------------------------------------------------------------------------------
/Documentation/Toast3.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mike-eason/WPF_ToastNotifications/HEAD/Documentation/Toast3.PNG
--------------------------------------------------------------------------------
/Documentation/Toast4.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mike-eason/WPF_ToastNotifications/HEAD/Documentation/Toast4.PNG
--------------------------------------------------------------------------------
/Documentation/Toast5.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mike-eason/WPF_ToastNotifications/HEAD/Documentation/Toast5.PNG
--------------------------------------------------------------------------------
/PeanutButter.Toasts/Icons/CrossWhite.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mike-eason/WPF_ToastNotifications/HEAD/PeanutButter.Toasts/Icons/CrossWhite.png
--------------------------------------------------------------------------------
/PeanutButter.Toast.Demo/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/PeanutButter.Toast.Demo/Properties/Settings.settings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/PeanutButter.Toasts/Properties/Settings.settings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/PeanutButter.Toast.Demo/App.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Configuration;
4 | using System.Data;
5 | using System.Linq;
6 | using System.Threading.Tasks;
7 | using System.Windows;
8 |
9 | namespace PeanutButter.Toast.Demo
10 | {
11 | ///
12 | /// Interaction logic for App.xaml
13 | ///
14 | public partial class App : Application
15 | {
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/PeanutButter.Toast.Demo/App.xaml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/PeanutButter.Toasts/ToastNotificationHost.xaml:
--------------------------------------------------------------------------------
1 |
20 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/PeanutButter.Toasts/Properties/Settings.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.42000
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace PeanutButter.Toast.Properties {
12 |
13 |
14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "14.0.0.0")]
16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
17 |
18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
19 |
20 | public static Settings Default {
21 | get {
22 | return defaultInstance;
23 | }
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/PeanutButter.Toast.Demo/Properties/Settings.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.42000
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace PeanutButter.Toast.Demo.Properties
12 | {
13 |
14 |
15 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
16 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
17 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase
18 | {
19 |
20 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
21 |
22 | public static Settings Default
23 | {
24 | get
25 | {
26 | return defaultInstance;
27 | }
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.InteropServices;
3 |
4 | // General Information about an assembly is controlled through the following
5 | // set of attributes. Change these attribute values to modify the information
6 | // associated with an assembly.
7 | [assembly: AssemblyTitle("PeanutButter.Toast")]
8 | [assembly: AssemblyDescription("A small framework for displaying simple, beautiful toast notifications in WPF.")]
9 | [assembly: AssemblyConfiguration("")]
10 | [assembly: AssemblyCompany("")]
11 | [assembly: AssemblyProduct("PeanutButter.Toast")]
12 | [assembly: AssemblyCopyright("Copyright © 2015")]
13 | [assembly: AssemblyTrademark("")]
14 | [assembly: AssemblyCulture("")]
15 |
16 | // Setting ComVisible to false makes the types in this assembly not visible
17 | // to COM components. If you need to access a type in this assembly from
18 | // COM, set the ComVisible attribute to true on that type.
19 | [assembly: ComVisible(false)]
20 |
21 | // The following GUID is for the ID of the typelib if this project is exposed to COM
22 | [assembly: Guid("28d2326e-2521-4530-be51-82df7dadbd2d")]
23 |
24 | // Version information for an assembly consists of the following four values:
25 | //
26 | // Major Version
27 | // Minor Version
28 | // Build Number
29 | // Revision
30 | //
31 | // You can specify all the values or you can default the Build and Revision Numbers
32 | // by using the '*' as shown below:
33 | // [assembly: AssemblyVersion("1.0.*")]
34 | [assembly: AssemblyVersion("1.0.0.0")]
35 | [assembly: AssemblyFileVersion("1.0.0.0")]
36 |
--------------------------------------------------------------------------------
/PeanutButter.Toasts/Toast.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Windows.Threading;
3 |
4 | namespace PeanutButter.Toast
5 | {
6 | internal class Toast
7 | {
8 | public event EventHandler ToastClosing;
9 |
10 | private DispatcherTimer _Timer;
11 | private ToastNotification _Notification;
12 |
13 | public Toast(ToastNotification notification)
14 | {
15 | _Notification = notification;
16 |
17 | _Notification.Dismissed += Notification_Dismissed;
18 | }
19 |
20 | private void Notification_Dismissed(object sender, EventArgs e)
21 | {
22 | OnToastClosing();
23 | }
24 |
25 | private void Timer_Tick(object sender, EventArgs e)
26 | {
27 | //Stop and close the window.
28 | _Timer.Stop();
29 |
30 | OnToastClosing();
31 | }
32 |
33 | public void Show(TimeSpan displayTime)
34 | {
35 | //Only start the timer if the notification is not persistent.
36 | if (!_Notification.IsPersistent)
37 | {
38 | //Set up the timer
39 | _Timer = new DispatcherTimer();
40 | _Timer.Interval = displayTime;
41 | _Timer.Tick += Timer_Tick;
42 |
43 | //Start the timer
44 | _Timer.Start();
45 | }
46 | }
47 |
48 | protected void OnToastClosing()
49 | {
50 | //Unsubscribe from the on dismiss event first (to avoid memory leaks)
51 | _Notification.Dismissed -= Notification_Dismissed;
52 |
53 | var eh = ToastClosing;
54 |
55 | if (eh != null)
56 | eh(this, _Notification);
57 | }
58 | }
59 | }
--------------------------------------------------------------------------------
/PeanutButter.Toast.Demo/MainWindow.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using System.Windows;
7 | using System.Windows.Controls;
8 | using System.Windows.Data;
9 | using System.Windows.Documents;
10 | using System.Windows.Input;
11 | using System.Windows.Media;
12 | using System.Windows.Media.Imaging;
13 | using System.Windows.Navigation;
14 | using System.Windows.Shapes;
15 |
16 | namespace PeanutButter.Toast.Demo
17 | {
18 | ///
19 | /// Interaction logic for MainWindow.xaml
20 | ///
21 | public partial class MainWindow : Window
22 | {
23 | Toaster _Toaster = new Toaster();
24 |
25 | public MainWindow()
26 | {
27 | InitializeComponent();
28 | }
29 |
30 | private void toastRequested(object sender, RoutedEventArgs e)
31 | {
32 | ToastTypes type = GetChosenToastType((Button)sender);
33 | string title = txtTitle.Text;
34 | string message = txtMessage.Text;
35 | bool isPersistent = (bool)chkPersistent.IsChecked;
36 | bool showInWindow = (bool)chkShowInWindow.IsChecked;
37 |
38 | if (showInWindow)
39 | {
40 | Rect bounds = new Rect(
41 | this.Left,
42 | this.Top,
43 | this.Width,
44 | this.Height);
45 |
46 | _Toaster.Show(title, message, type, bounds, isPersistent);
47 | }
48 | else
49 | _Toaster.Show(title, message, type, isPersistent: isPersistent);
50 | }
51 |
52 | private ToastTypes GetChosenToastType(Button buttonClicked)
53 | {
54 | switch(buttonClicked.Name)
55 | {
56 | case "btnSuccess":
57 | return ToastTypes.Success;
58 | case "btnError":
59 | return ToastTypes.Error;
60 | case "btnWarning":
61 | return ToastTypes.Warning;
62 | case "btnInfo":
63 | return ToastTypes.Info;
64 | }
65 |
66 | throw new NotImplementedException("This button has not been implemented");
67 | }
68 | }
69 | }
--------------------------------------------------------------------------------
/PeanutButter.Toasts/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Resources;
3 | using System.Runtime.CompilerServices;
4 | using System.Runtime.InteropServices;
5 | using System.Windows;
6 |
7 | // General Information about an assembly is controlled through the following
8 | // set of attributes. Change these attribute values to modify the information
9 | // associated with an assembly.
10 | [assembly: AssemblyTitle("PeanutButter.Toast")]
11 | [assembly: AssemblyDescription("")]
12 | [assembly: AssemblyConfiguration("")]
13 | [assembly: AssemblyCompany("")]
14 | [assembly: AssemblyProduct("PeanutButter.Toast")]
15 | [assembly: AssemblyCopyright("Copyright © 2016")]
16 | [assembly: AssemblyTrademark("")]
17 | [assembly: AssemblyCulture("")]
18 |
19 | // Setting ComVisible to false makes the types in this assembly not visible
20 | // to COM components. If you need to access a type in this assembly from
21 | // COM, set the ComVisible attribute to true on that type.
22 | [assembly: ComVisible(false)]
23 |
24 | //In order to begin building localizable applications, set
25 | //CultureYouAreCodingWith in your .csproj file
26 | //inside a . For example, if you are using US english
27 | //in your source files, set the to en-US. Then uncomment
28 | //the NeutralResourceLanguage attribute below. Update the "en-US" in
29 | //the line below to match the UICulture setting in the project file.
30 |
31 | //[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]
32 |
33 |
34 | [assembly:ThemeInfo(
35 | ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
36 | //(used if a resource is not found in the page,
37 | // or application resource dictionaries)
38 | ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
39 | //(used if a resource is not found in the page,
40 | // app, or any theme specific resource dictionaries)
41 | )]
42 |
43 |
44 | // Version information for an assembly consists of the following four values:
45 | //
46 | // Major Version
47 | // Minor Version
48 | // Build Number
49 | // Revision
50 | //
51 | // You can specify all the values or you can default the Build and Revision Numbers
52 | // by using the '*' as shown below:
53 | // [assembly: AssemblyVersion("1.0.*")]
54 | [assembly: AssemblyVersion("1.0.0.0")]
55 | [assembly: AssemblyFileVersion("1.0.0.0")]
56 |
--------------------------------------------------------------------------------
/PeanutButter.Toast.Demo/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Resources;
3 | using System.Runtime.CompilerServices;
4 | using System.Runtime.InteropServices;
5 | using System.Windows;
6 |
7 | // General Information about an assembly is controlled through the following
8 | // set of attributes. Change these attribute values to modify the information
9 | // associated with an assembly.
10 | [assembly: AssemblyTitle("PeanutButter.Toast.Demo")]
11 | [assembly: AssemblyDescription("")]
12 | [assembly: AssemblyConfiguration("")]
13 | [assembly: AssemblyCompany("")]
14 | [assembly: AssemblyProduct("PeanutButter.Toast.Demo")]
15 | [assembly: AssemblyCopyright("Copyright © 2016")]
16 | [assembly: AssemblyTrademark("")]
17 | [assembly: AssemblyCulture("")]
18 |
19 | // Setting ComVisible to false makes the types in this assembly not visible
20 | // to COM components. If you need to access a type in this assembly from
21 | // COM, set the ComVisible attribute to true on that type.
22 | [assembly: ComVisible(false)]
23 |
24 | //In order to begin building localizable applications, set
25 | //CultureYouAreCodingWith in your .csproj file
26 | //inside a . For example, if you are using US english
27 | //in your source files, set the to en-US. Then uncomment
28 | //the NeutralResourceLanguage attribute below. Update the "en-US" in
29 | //the line below to match the UICulture setting in the project file.
30 |
31 | //[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]
32 |
33 |
34 | [assembly: ThemeInfo(
35 | ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
36 | //(used if a resource is not found in the page,
37 | // or application resource dictionaries)
38 | ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
39 | //(used if a resource is not found in the page,
40 | // app, or any theme specific resource dictionaries)
41 | )]
42 |
43 |
44 | // Version information for an assembly consists of the following four values:
45 | //
46 | // Major Version
47 | // Minor Version
48 | // Build Number
49 | // Revision
50 | //
51 | // You can specify all the values or you can default the Build and Revision Numbers
52 | // by using the '*' as shown below:
53 | // [assembly: AssemblyVersion("1.0.*")]
54 | [assembly: AssemblyVersion("1.0.0.0")]
55 | [assembly: AssemblyFileVersion("1.0.0.0")]
56 |
--------------------------------------------------------------------------------
/PeanutButter.Toasts/Properties/Resources.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.42000
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace PeanutButter.Toast.Properties {
12 | using System;
13 |
14 |
15 | ///
16 | /// A strongly-typed resource class, for looking up localized strings, etc.
17 | ///
18 | // This class was auto-generated by the StronglyTypedResourceBuilder
19 | // class via a tool like ResGen or Visual Studio.
20 | // To add or remove a member, edit your .ResX file then rerun ResGen
21 | // with the /str option, or rebuild your VS project.
22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
25 | internal class Resources {
26 |
27 | private static global::System.Resources.ResourceManager resourceMan;
28 |
29 | private static global::System.Globalization.CultureInfo resourceCulture;
30 |
31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
32 | internal Resources() {
33 | }
34 |
35 | ///
36 | /// Returns the cached ResourceManager instance used by this class.
37 | ///
38 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
39 | internal static global::System.Resources.ResourceManager ResourceManager {
40 | get {
41 | if (object.ReferenceEquals(resourceMan, null)) {
42 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("PeanutButter.Toast.Properties.Resources", typeof(Resources).Assembly);
43 | resourceMan = temp;
44 | }
45 | return resourceMan;
46 | }
47 | }
48 |
49 | ///
50 | /// Overrides the current thread's CurrentUICulture property for all
51 | /// resource lookups using this strongly typed resource class.
52 | ///
53 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
54 | internal static global::System.Globalization.CultureInfo Culture {
55 | get {
56 | return resourceCulture;
57 | }
58 | set {
59 | resourceCulture = value;
60 | }
61 | }
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/PeanutButter.Toast.Demo/Properties/Resources.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.42000
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace PeanutButter.Toast.Demo.Properties
12 | {
13 |
14 |
15 | ///
16 | /// A strongly-typed resource class, for looking up localized strings, etc.
17 | ///
18 | // This class was auto-generated by the StronglyTypedResourceBuilder
19 | // class via a tool like ResGen or Visual Studio.
20 | // To add or remove a member, edit your .ResX file then rerun ResGen
21 | // with the /str option, or rebuild your VS project.
22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
25 | internal class Resources
26 | {
27 |
28 | private static global::System.Resources.ResourceManager resourceMan;
29 |
30 | private static global::System.Globalization.CultureInfo resourceCulture;
31 |
32 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
33 | internal Resources()
34 | {
35 | }
36 |
37 | ///
38 | /// Returns the cached ResourceManager instance used by this class.
39 | ///
40 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
41 | internal static global::System.Resources.ResourceManager ResourceManager
42 | {
43 | get
44 | {
45 | if ((resourceMan == null))
46 | {
47 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("PeanutButter.Toast.Demo.Properties.Resources", typeof(Resources).Assembly);
48 | resourceMan = temp;
49 | }
50 | return resourceMan;
51 | }
52 | }
53 |
54 | ///
55 | /// Overrides the current thread's CurrentUICulture property for all
56 | /// resource lookups using this strongly typed resource class.
57 | ///
58 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
59 | internal static global::System.Globalization.CultureInfo Culture
60 | {
61 | get
62 | {
63 | return resourceCulture;
64 | }
65 | set
66 | {
67 | resourceCulture = value;
68 | }
69 | }
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/PeanutButter.Toasts/ToastNotificationHost.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.ObjectModel;
3 | using System.Windows;
4 | using System.Windows.Media.Animation;
5 |
6 | namespace PeanutButter.Toast
7 | {
8 | ///
9 | /// Interaction logic for ToastNotificationHost.xaml
10 | ///
11 | public partial class ToastNotificationHost : Window
12 | {
13 | public ObservableCollection Toasts
14 | {
15 | get { return (ObservableCollection)GetValue(ToastsProperty); }
16 | set { SetValue(ToastsProperty, value); }
17 | }
18 |
19 | public static readonly DependencyProperty ToastsProperty =
20 | DependencyProperty.Register("Toasts", typeof(ObservableCollection), typeof(ToastNotificationHost), new PropertyMetadata(new ObservableCollection()));
21 |
22 | public Rect? DisplayOrigin
23 | {
24 | get { return (Rect?)GetValue(DisplayOriginProperty); }
25 | set { SetValue(DisplayOriginProperty, value); }
26 | }
27 |
28 | // Using a DependencyProperty as the backing store for DisplayOrigin. This enables animation, styling, binding, etc...
29 | public static readonly DependencyProperty DisplayOriginProperty =
30 | DependencyProperty.Register("DisplayOrigin", typeof(Rect?), typeof(ToastNotificationHost), new PropertyMetadata(null, new PropertyChangedCallback(DisplayOriginChanged)));
31 |
32 | private static void DisplayOriginChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
33 | {
34 | ToastNotificationHost host = (ToastNotificationHost)d;
35 |
36 | host.Reposition();
37 | }
38 |
39 | public void Reposition()
40 | {
41 | Rect area;
42 | int offset = 12;
43 |
44 | if (DisplayOrigin != null)
45 | area = (Rect)DisplayOrigin;
46 | else
47 | area = System.Windows.SystemParameters.WorkArea;
48 |
49 | //Display the toast at the top right of the area.
50 | this.Left = area.Right - this.Width - offset;
51 | this.Top = area.Top + offset;
52 | }
53 |
54 | public ToastNotificationHost()
55 | {
56 | InitializeComponent();
57 |
58 | this.Closing += ToastNotificationHost_Closing;
59 | this.Loaded += ToastNotification_Loaded;
60 | }
61 |
62 | private void ToastNotificationHost_Closing(object sender, System.ComponentModel.CancelEventArgs e)
63 | {
64 | Closing -= ToastNotificationHost_Closing;
65 | e.Cancel = true;
66 | var anim = new DoubleAnimation(0, (Duration)TimeSpan.FromSeconds(0.25));
67 | anim.Completed += (s, _) => this.Close();
68 | this.BeginAnimation(UIElement.OpacityProperty, anim);
69 | }
70 |
71 | private void ToastNotification_Loaded(object sender, RoutedEventArgs e)
72 | {
73 | Reposition();
74 | }
75 | }
76 | }
--------------------------------------------------------------------------------
/PeanutButter.Toast.Demo/MainWindow.xaml:
--------------------------------------------------------------------------------
1 |
12 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
32 |
33 |
35 |
40 |
41 |
43 |
47 |
48 |
50 |
54 |
55 |
62 |
63 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
--------------------------------------------------------------------------------
/PeanutButter.Toasts/Toaster.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Windows;
3 |
4 | namespace PeanutButter.Toast
5 | {
6 | public class Toaster : IToaster
7 | {
8 | private const string _DEFAULT_TITLE = "Operation Failed";
9 |
10 | private ToastNotificationHost _HOST;
11 |
12 | public void Show(
13 | Exception error,
14 | Rect? parentContainer = null,
15 | bool isPersistent = false)
16 | {
17 | Show(_DEFAULT_TITLE, error.Message, parentContainer, isPersistent);
18 | }
19 |
20 | public void Show(
21 | string title,
22 | Exception error,
23 | Rect? parentContainer = null,
24 | bool isPersistent = false)
25 | {
26 | Show(title, error.Message, parentContainer, isPersistent);
27 | }
28 |
29 | public void Show(
30 | string title,
31 | string message,
32 | Rect? parentContainer = null,
33 | bool isPersistent = false)
34 | {
35 | Show(title, message, ToastTypes.Error, parentContainer, isPersistent);
36 | }
37 |
38 | public void Show(
39 | string title,
40 | string message,
41 | ToastTypes toastType,
42 | Rect? parentContainer = null,
43 | bool isPersistent = false)
44 | {
45 | Show(title, message, toastType, new TimeSpan(0, 0, 5), parentContainer, isPersistent);
46 | }
47 |
48 | public void Show(
49 | string title,
50 | string message,
51 | ToastTypes toastType,
52 | TimeSpan displayTime,
53 | Rect? parentContainer = null,
54 | bool isPersistent = false)
55 | {
56 | //Show the host window
57 | ShowHost(parentContainer);
58 |
59 | //Create a new toast control
60 | ToastNotification notification = new ToastNotification()
61 | {
62 | Title = title,
63 | Message = message,
64 | ToastType = toastType,
65 | IsPersistent = isPersistent
66 | };
67 |
68 | //Create a toast and accompanying dispatcher timer.
69 | Toast toast = new Toast(notification);
70 | toast.ToastClosing += Toast_ToastClosing;
71 |
72 | //Add the toast to the host window
73 | _HOST.Toasts.Add(notification);
74 |
75 | //display it for X seconds
76 | toast.Show(displayTime);
77 | }
78 |
79 | private void ShowHost(Rect? container)
80 | {
81 | //If the current host window is null, create it.
82 | if (_HOST == null)
83 | {
84 | _HOST = new ToastNotificationHost()
85 | {
86 | DisplayOrigin = container
87 | };
88 |
89 | _HOST.Show();
90 | _HOST.Closed += _HOST_Closed;
91 | }
92 | //Otherwise, set it's display location and origin.
93 | else
94 | _HOST.DisplayOrigin = container;
95 |
96 | _HOST.Reposition();
97 |
98 | //Display the window
99 | if (!_HOST.IsVisible)
100 | _HOST.Visibility = Visibility.Visible;
101 | }
102 |
103 | private void Toast_ToastClosing(object sender, ToastNotification e)
104 | {
105 | //Remove the toast from the host window
106 | _HOST.Toasts.Remove(e);
107 |
108 | //If there are no more toasts to show, then close the host window
109 | if (_HOST.Toasts.Count == 0)
110 | _HOST.Visibility = Visibility.Collapsed;
111 | }
112 |
113 | private void _HOST_Closed(object sender, EventArgs e)
114 | {
115 | //Reset the host.
116 | _HOST.Closed -= _HOST_Closed;
117 | _HOST = null;
118 | }
119 | }
120 | }
--------------------------------------------------------------------------------
/PeanutButter.Toasts/IToaster.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using System.Windows;
7 |
8 | namespace PeanutButter.Toast
9 | {
10 | public enum ToastTypes
11 | {
12 | Error,
13 | Success,
14 | Warning,
15 | Info
16 | }
17 |
18 | public interface IToaster
19 | {
20 | ///
21 | /// Show an error toast notification for 5 seconds.
22 | ///
23 | /// The error to display. The content will be the Message property on the exception.
24 | /// The container to display the toast within. Leave this as null to use the primary monitor.
25 | /// If true, the toast will remain visible until the user closes it.
26 | void Show(
27 | Exception error,
28 | Rect? parentContainer = null,
29 | bool isPersistent = false);
30 |
31 | ///
32 | /// Show an error toast notification for 5 seconds.
33 | ///
34 | /// The title of the toast.
35 | /// The error to display. The content will be the Message property on the exception.
36 | /// The container to display the toast within. Leave this as null to use the primary monitor.
37 | /// If true, the toast will remain visible until the user closes it.
38 | void Show(
39 | string title,
40 | Exception error,
41 | Rect? parentContainer = null,
42 | bool isPersistent = false);
43 |
44 | ///
45 | /// Show an error toast notification for 5 seconds.
46 | ///
47 | /// The title of the toast.
48 | /// The message to display.
49 | /// The container to display the toast within. Leave this as null to use the primary monitor.
50 | /// If true, the toast will remain visible until the user closes it.
51 | void Show(
52 | string title,
53 | string message,
54 | Rect? parentContainer = null,
55 | bool isPersistent = false);
56 |
57 | ///
58 | /// Show a toast notification for 5 seconds.
59 | ///
60 | /// The title of the toast.
61 | /// The message to display.
62 | /// The toast type to be displayed.
63 | /// The container to display the toast within. Leave this as null to use the primary monitor.
64 | /// If true, the toast will remain visible until the user closes it.
65 | void Show(
66 | string title,
67 | string message,
68 | ToastTypes toastType,
69 | Rect? parentContainer = null,
70 | bool isPersistent = false);
71 |
72 | ///
73 | /// Show a toast notification for a given time frame.
74 | ///
75 | /// The title of the toast.
76 | /// The message to display.
77 | /// The toast type to be displayed.
78 | /// The duration to show the toast for.
79 | /// The container to display the toast within. Leave this as null to use the primary monitor.
80 | /// If true, the toast will remain visible until the user closes it.
81 | void Show(
82 | string title,
83 | string message,
84 | ToastTypes toastType,
85 | TimeSpan displayTime,
86 | Rect? parentContainer = null,
87 | bool isPersistent = false);
88 | }
89 | }
90 |
--------------------------------------------------------------------------------
/PeanutButter.Toast.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 14
4 | VisualStudioVersion = 14.0.24720.0
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PeanutButter.Toast", "PeanutButter.Toasts\PeanutButter.Toast.csproj", "{B871F316-8338-4B69-90A2-B0E3259F0E58}"
7 | EndProject
8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PeanutButter.Toast.Demo", "PeanutButter.Toast.Demo\PeanutButter.Toast.Demo.csproj", "{65A57511-30F1-472A-8D28-52A67CEF6766}"
9 | EndProject
10 | Global
11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
12 | Debug|Any CPU = Debug|Any CPU
13 | LocalIIS_Richard|Any CPU = LocalIIS_Richard|Any CPU
14 | Release|Any CPU = Release|Any CPU
15 | ReleaseDebug|Any CPU = ReleaseDebug|Any CPU
16 | ReleaseShoreham|Any CPU = ReleaseShoreham|Any CPU
17 | Slinfold|Any CPU = Slinfold|Any CPU
18 | Test|Any CPU = Test|Any CPU
19 | WPF_Release|Any CPU = WPF_Release|Any CPU
20 | WPF|Any CPU = WPF|Any CPU
21 | EndGlobalSection
22 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
23 | {B871F316-8338-4B69-90A2-B0E3259F0E58}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
24 | {B871F316-8338-4B69-90A2-B0E3259F0E58}.Debug|Any CPU.Build.0 = Debug|Any CPU
25 | {B871F316-8338-4B69-90A2-B0E3259F0E58}.LocalIIS_Richard|Any CPU.ActiveCfg = Release|Any CPU
26 | {B871F316-8338-4B69-90A2-B0E3259F0E58}.LocalIIS_Richard|Any CPU.Build.0 = Release|Any CPU
27 | {B871F316-8338-4B69-90A2-B0E3259F0E58}.Release|Any CPU.ActiveCfg = Release|Any CPU
28 | {B871F316-8338-4B69-90A2-B0E3259F0E58}.Release|Any CPU.Build.0 = Release|Any CPU
29 | {B871F316-8338-4B69-90A2-B0E3259F0E58}.ReleaseDebug|Any CPU.ActiveCfg = Release|Any CPU
30 | {B871F316-8338-4B69-90A2-B0E3259F0E58}.ReleaseDebug|Any CPU.Build.0 = Release|Any CPU
31 | {B871F316-8338-4B69-90A2-B0E3259F0E58}.ReleaseShoreham|Any CPU.ActiveCfg = Release|Any CPU
32 | {B871F316-8338-4B69-90A2-B0E3259F0E58}.ReleaseShoreham|Any CPU.Build.0 = Release|Any CPU
33 | {B871F316-8338-4B69-90A2-B0E3259F0E58}.Slinfold|Any CPU.ActiveCfg = Release|Any CPU
34 | {B871F316-8338-4B69-90A2-B0E3259F0E58}.Slinfold|Any CPU.Build.0 = Release|Any CPU
35 | {B871F316-8338-4B69-90A2-B0E3259F0E58}.Test|Any CPU.ActiveCfg = Release|Any CPU
36 | {B871F316-8338-4B69-90A2-B0E3259F0E58}.Test|Any CPU.Build.0 = Release|Any CPU
37 | {B871F316-8338-4B69-90A2-B0E3259F0E58}.WPF_Release|Any CPU.ActiveCfg = Release|Any CPU
38 | {B871F316-8338-4B69-90A2-B0E3259F0E58}.WPF_Release|Any CPU.Build.0 = Release|Any CPU
39 | {B871F316-8338-4B69-90A2-B0E3259F0E58}.WPF|Any CPU.ActiveCfg = Release|Any CPU
40 | {B871F316-8338-4B69-90A2-B0E3259F0E58}.WPF|Any CPU.Build.0 = Release|Any CPU
41 | {65A57511-30F1-472A-8D28-52A67CEF6766}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
42 | {65A57511-30F1-472A-8D28-52A67CEF6766}.Debug|Any CPU.Build.0 = Debug|Any CPU
43 | {65A57511-30F1-472A-8D28-52A67CEF6766}.LocalIIS_Richard|Any CPU.ActiveCfg = Release|Any CPU
44 | {65A57511-30F1-472A-8D28-52A67CEF6766}.LocalIIS_Richard|Any CPU.Build.0 = Release|Any CPU
45 | {65A57511-30F1-472A-8D28-52A67CEF6766}.Release|Any CPU.ActiveCfg = Release|Any CPU
46 | {65A57511-30F1-472A-8D28-52A67CEF6766}.Release|Any CPU.Build.0 = Release|Any CPU
47 | {65A57511-30F1-472A-8D28-52A67CEF6766}.ReleaseDebug|Any CPU.ActiveCfg = Release|Any CPU
48 | {65A57511-30F1-472A-8D28-52A67CEF6766}.ReleaseDebug|Any CPU.Build.0 = Release|Any CPU
49 | {65A57511-30F1-472A-8D28-52A67CEF6766}.ReleaseShoreham|Any CPU.ActiveCfg = Release|Any CPU
50 | {65A57511-30F1-472A-8D28-52A67CEF6766}.ReleaseShoreham|Any CPU.Build.0 = Release|Any CPU
51 | {65A57511-30F1-472A-8D28-52A67CEF6766}.Slinfold|Any CPU.ActiveCfg = Release|Any CPU
52 | {65A57511-30F1-472A-8D28-52A67CEF6766}.Slinfold|Any CPU.Build.0 = Release|Any CPU
53 | {65A57511-30F1-472A-8D28-52A67CEF6766}.Test|Any CPU.ActiveCfg = Release|Any CPU
54 | {65A57511-30F1-472A-8D28-52A67CEF6766}.Test|Any CPU.Build.0 = Release|Any CPU
55 | {65A57511-30F1-472A-8D28-52A67CEF6766}.WPF_Release|Any CPU.ActiveCfg = Release|Any CPU
56 | {65A57511-30F1-472A-8D28-52A67CEF6766}.WPF_Release|Any CPU.Build.0 = Release|Any CPU
57 | {65A57511-30F1-472A-8D28-52A67CEF6766}.WPF|Any CPU.ActiveCfg = Release|Any CPU
58 | {65A57511-30F1-472A-8D28-52A67CEF6766}.WPF|Any CPU.Build.0 = Release|Any CPU
59 | EndGlobalSection
60 | GlobalSection(SolutionProperties) = preSolution
61 | HideSolutionNode = FALSE
62 | EndGlobalSection
63 | EndGlobal
64 |
--------------------------------------------------------------------------------
/PeanutButter.Toasts/PeanutButter.Toast.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {B871F316-8338-4B69-90A2-B0E3259F0E58}
8 | library
9 | Properties
10 | PeanutButter.Toast
11 | PeanutButter.Toast
12 | v4.5.2
13 | 512
14 | {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
15 | 4
16 |
17 |
18 | true
19 | full
20 | false
21 | bin\Debug\
22 | DEBUG;TRACE
23 | prompt
24 | 4
25 |
26 |
27 | pdbonly
28 | true
29 | bin\Release\
30 | TRACE
31 | prompt
32 | 4
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 | 4.0
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 | ToastNotificationHost.xaml
55 |
56 |
57 | MSBuild:Compile
58 | Designer
59 |
60 |
61 | Code
62 |
63 |
64 | MSBuild:Compile
65 | Designer
66 |
67 |
68 |
69 |
70 |
71 | Code
72 |
73 |
74 | True
75 | True
76 | Resources.resx
77 |
78 |
79 | True
80 | Settings.settings
81 | True
82 |
83 |
84 | ResXFileCodeGenerator
85 | Resources.Designer.cs
86 |
87 |
88 | SettingsSingleFileGenerator
89 | Settings.Designer.cs
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
104 |
--------------------------------------------------------------------------------
/PeanutButter.Toast.Demo/PeanutButter.Toast.Demo.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {65A57511-30F1-472A-8D28-52A67CEF6766}
8 | WinExe
9 | Properties
10 | PeanutButter.Toast.Demo
11 | PeanutButter.Toast.Demo
12 | v4.5.2
13 | 512
14 | {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
15 | 4
16 | true
17 |
18 |
19 | AnyCPU
20 | true
21 | full
22 | false
23 | bin\Debug\
24 | DEBUG;TRACE
25 | prompt
26 | 4
27 |
28 |
29 | AnyCPU
30 | pdbonly
31 | true
32 | bin\Release\
33 | TRACE
34 | prompt
35 | 4
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 | 4.0
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 | MSBuild:Compile
56 | Designer
57 |
58 |
59 | MSBuild:Compile
60 | Designer
61 |
62 |
63 | App.xaml
64 | Code
65 |
66 |
67 | MainWindow.xaml
68 | Code
69 |
70 |
71 |
72 |
73 | Code
74 |
75 |
76 | True
77 | True
78 | Resources.resx
79 |
80 |
81 | True
82 | Settings.settings
83 | True
84 |
85 |
86 | ResXFileCodeGenerator
87 | Resources.Designer.cs
88 |
89 |
90 | SettingsSingleFileGenerator
91 | Settings.Designer.cs
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 | {b871f316-8338-4b69-90a2-b0e3259f0e58}
101 | PeanutButter.Toast
102 |
103 |
104 |
105 |
112 |
--------------------------------------------------------------------------------
/gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 |
4 | .vs/
5 |
6 | # User-specific files
7 | *.suo
8 | *.user
9 | *.userosscache
10 | *.sln.docstates
11 |
12 | # User-specific files (MonoDevelop/Xamarin Studio)
13 | *.userprefs
14 |
15 | # Build results
16 | [Dd]ebug/
17 | [Dd]ebugPublic/
18 | [Rr]elease/
19 | [Rr]eleases/
20 | x64/
21 | x86/
22 | bld/
23 | [Bb]in/
24 | [Oo]bj/
25 | [Ll]og/
26 |
27 | # Visual Studio 2015 cache/options directory
28 | .vs/
29 | # Uncomment if you have tasks that create the project's static files in wwwroot
30 | #wwwroot/
31 |
32 | # MSTest test Results
33 | [Tt]est[Rr]esult*/
34 | [Bb]uild[Ll]og.*
35 |
36 | # NUNIT
37 | *.VisualState.xml
38 | TestResult.xml
39 |
40 | # Build Results of an ATL Project
41 | [Dd]ebugPS/
42 | [Rr]eleasePS/
43 | dlldata.c
44 |
45 | # DNX
46 | project.lock.json
47 | artifacts/
48 |
49 | *_i.c
50 | *_p.c
51 | *_i.h
52 | *.ilk
53 | *.meta
54 | *.obj
55 | *.pch
56 | *.pdb
57 | *.pgc
58 | *.pgd
59 | *.rsp
60 | *.sbr
61 | *.tlb
62 | *.tli
63 | *.tlh
64 | *.tmp
65 | *.tmp_proj
66 | *.log
67 | *.vspscc
68 | *.vssscc
69 | .builds
70 | *.pidb
71 | *.svclog
72 | *.scc
73 |
74 | # Chutzpah Test files
75 | _Chutzpah*
76 |
77 | # Visual C++ cache files
78 | ipch/
79 | *.aps
80 | *.ncb
81 | *.opendb
82 | *.opensdf
83 | *.sdf
84 | *.cachefile
85 |
86 | # Visual Studio profiler
87 | *.psess
88 | *.vsp
89 | *.vspx
90 | *.sap
91 |
92 | # TFS 2012 Local Workspace
93 | $tf/
94 |
95 | # Guidance Automation Toolkit
96 | *.gpState
97 |
98 | # ReSharper is a .NET coding add-in
99 | _ReSharper*/
100 | *.[Rr]e[Ss]harper
101 | *.DotSettings.user
102 |
103 | # JustCode is a .NET coding add-in
104 | .JustCode
105 |
106 | # TeamCity is a build add-in
107 | _TeamCity*
108 |
109 | # DotCover is a Code Coverage Tool
110 | *.dotCover
111 |
112 | # NCrunch
113 | _NCrunch_*
114 | .*crunch*.local.xml
115 | nCrunchTemp_*
116 |
117 | # MightyMoose
118 | *.mm.*
119 | AutoTest.Net/
120 |
121 | # Web workbench (sass)
122 | .sass-cache/
123 |
124 | # Installshield output folder
125 | [Ee]xpress/
126 |
127 | # DocProject is a documentation generator add-in
128 | DocProject/buildhelp/
129 | DocProject/Help/*.HxT
130 | DocProject/Help/*.HxC
131 | DocProject/Help/*.hhc
132 | DocProject/Help/*.hhk
133 | DocProject/Help/*.hhp
134 | DocProject/Help/Html2
135 | DocProject/Help/html
136 |
137 | # Click-Once directory
138 | publish/
139 |
140 | # Publish Web Output
141 | *.[Pp]ublish.xml
142 | *.azurePubxml
143 | # TODO: Comment the next line if you want to checkin your web deploy settings
144 | # but database connection strings (with potential passwords) will be unencrypted
145 | *.pubxml
146 | *.publishproj
147 |
148 | # NuGet Packages
149 | *.nupkg
150 | # The packages folder can be ignored because of Package Restore
151 | **/packages/*
152 | # except build/, which is used as an MSBuild target.
153 | !**/packages/build/
154 | # Uncomment if necessary however generally it will be regenerated when needed
155 | #!**/packages/repositories.config
156 | # NuGet v3's project.json files produces more ignoreable files
157 | *.nuget.props
158 | *.nuget.targets
159 |
160 | # Microsoft Azure Build Output
161 | csx/
162 | *.build.csdef
163 |
164 | # Microsoft Azure Emulator
165 | ecf/
166 | rcf/
167 |
168 | # Windows Store app package directories and files
169 | AppPackages/
170 | BundleArtifacts/
171 | Package.StoreAssociation.xml
172 | _pkginfo.txt
173 |
174 | # Visual Studio cache files
175 | # files ending in .cache can be ignored
176 | *.[Cc]ache
177 | # but keep track of directories ending in .cache
178 | !*.[Cc]ache/
179 |
180 | # Others
181 | ClientBin/
182 | ~$*
183 | *~
184 | *.dbmdl
185 | *.dbproj.schemaview
186 | *.pfx
187 | *.publishsettings
188 | node_modules/
189 | orleans.codegen.cs
190 |
191 | # Since there are multiple workflows, uncomment next line to ignore bower_components
192 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
193 | #bower_components/
194 |
195 | # RIA/Silverlight projects
196 | Generated_Code/
197 |
198 | # Backup & report files from converting an old project file
199 | # to a newer Visual Studio version. Backup files are not needed,
200 | # because we have git ;-)
201 | _UpgradeReport_Files/
202 | Backup*/
203 | UpgradeLog*.XML
204 | UpgradeLog*.htm
205 |
206 | # SQL Server files
207 | *.mdf
208 | *.ldf
209 |
210 | # Business Intelligence projects
211 | *.rdl.data
212 | *.bim.layout
213 | *.bim_*.settings
214 |
215 | # Microsoft Fakes
216 | FakesAssemblies/
217 |
218 | # GhostDoc plugin setting file
219 | *.GhostDoc.xml
220 |
221 | # Node.js Tools for Visual Studio
222 | .ntvs_analysis.dat
223 |
224 | # Visual Studio 6 build log
225 | *.plg
226 |
227 | # Visual Studio 6 workspace options file
228 | *.opt
229 |
230 | # Visual Studio LightSwitch build output
231 | **/*.HTMLClient/GeneratedArtifacts
232 | **/*.DesktopClient/GeneratedArtifacts
233 | **/*.DesktopClient/ModelManifest.xml
234 | **/*.Server/GeneratedArtifacts
235 | **/*.Server/ModelManifest.xml
236 | _Pvt_Extensions
237 |
238 | # Paket dependency manager
239 | .paket/paket.exe
240 | paket-files/
241 |
242 | # FAKE - F# Make
243 | .fake/
244 |
245 | # JetBrains Rider
246 | .idea/
247 | *.sln.iml
248 |
249 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # WPF Toast Notifications
2 |
3 | This is a project which provides simple, beautiful toast notifications for WPF desktop applications.
4 |
5 | [](https://gyazo.com/7553a0bda0743cfd10aad83fa6c4055d)
6 |
7 | #### Getting Started
8 |
9 | Here's how to add this project to your solution:
10 |
11 | 1. Download and extract the project.
12 | 2. Add the `.csproj` to your solution.
13 | 3. Rebuild the project.
14 |
15 | Alternatively, you could build the project on it's own and add a reference to the output DLL in
16 | the `bin` folder from your solution.
17 |
18 | ## Code Examples
19 |
20 | To create a simple toast, use the following code:
21 |
22 | ```
23 | using PeanutButter.Toast;
24 |
25 | ...
26 |
27 | string title = "Hello World!";
28 | string message = "This is a test";
29 | ToastTypes type = ToastTypes.Info;
30 |
31 | Toaster toaster = new Toaster();
32 | toaster.Show(title, message, type);
33 | ```
34 |
35 | 
36 |
37 | #### Toasting an Exception
38 |
39 | You can display a toast notification to display the `Message` inside an `Exception`:
40 |
41 | ```
42 | catch (Exception ex)
43 | {
44 | toaster.Show(ex);
45 | }
46 | ```
47 |
48 | *Or*
49 |
50 | ```
51 | catch (Exception ex)
52 | {
53 | toaster.Show("Something Failed!", ex);
54 | }
55 | ```
56 |
57 | 
58 |
59 | #### Toast Within Bounds
60 |
61 | If you want to display a toast inside the bounds of the window, you can pass in the window location to the
62 | `parentContainer` parameter:
63 |
64 | ```
65 | Rect windowBounds = new Rect(
66 | this.Left,
67 | this.Top,
68 | this.Width,
69 | this.Height);
70 |
71 | toaster.Show(title, message, type, windowBounds);
72 | ```
73 |
74 | #### Persistent Toasts
75 |
76 | Sometimes you might want your toast to stick around until the user manually closes it. You can pass in `true`
77 | into the `isPersistent` parameter:
78 |
79 | ```
80 | toaster.Show(title, message, type, isPersistent: true);
81 | ```
82 |
83 | 
84 |
85 | #### Display Toasts For Longer
86 |
87 | Toasts will be displayed for 5 seconds by default, if you want to extend this period you can pass in a `TimeSpan`
88 | into the `displayTime` parameter:
89 |
90 | ```
91 | //10 seconds
92 | TimeSpan displayTime = new TimeSpan(10000);
93 |
94 | toaster.Show(title, message, type, displayTime);
95 | ```
96 |
97 | 
98 |
99 | #### Changing The Toast Template
100 |
101 | The toast can be restyled using the standard WPF style overriding:
102 |
103 | ```
104 | xmlns:toast="clr-namespace:PeanutButter.Toast;assembly=PeanutButter.Toast"
105 |
106 | ...
107 |
108 |
112 | ```
113 |
114 | Here is the result:
115 |
116 | 
117 |
118 | When overriding the `Template`, there is a named `Button` called `PART_DismissButton`. This is optional however if present, the `Click` event will automatically be registered.
119 |
120 | ## Mocking and Unit Testing
121 |
122 | For unit testing, I recommend that you first ensure that any `Toaster` objects are added to your classes using
123 | `dependency injection`, this will prevent any real toasts from being displayed inside unit tests.
124 |
125 | ```
126 | private IToaster _toaster;
127 |
128 | public MyClass(IToaster toaster)
129 | {
130 | _toaster = toaster;
131 | }
132 | ```
133 |
134 | The method of `dependency injection` is up to you, however this will allow you to make use of the interface `IToaster`
135 | which can be mocked. For example using the `NSubstitute` framework.
136 |
137 | ```
138 | IToaster toaster = Substitute.For();
139 | ```
140 |
141 | ## License
142 |
143 | MIT License
144 |
145 | Copyright (c) 2016 Mike Eason
146 |
147 | Permission is hereby granted, free of charge, to any person obtaining a copy
148 | of this software and associated documentation files (the "Software"), to deal
149 | in the Software without restriction, including without limitation the rights
150 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
151 | copies of the Software, and to permit persons to whom the Software is
152 | furnished to do so, subject to the following conditions:
153 |
154 | The above copyright notice and this permission notice shall be included in all
155 | copies or substantial portions of the Software.
156 |
157 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
158 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
159 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
160 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
161 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
162 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
163 | SOFTWARE.
164 |
--------------------------------------------------------------------------------
/PeanutButter.Toasts/Properties/Resources.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 | text/microsoft-resx
107 |
108 |
109 | 2.0
110 |
111 |
112 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
113 |
114 |
115 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
116 |
117 |
--------------------------------------------------------------------------------
/PeanutButter.Toast.Demo/Properties/Resources.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 | text/microsoft-resx
107 |
108 |
109 | 2.0
110 |
111 |
112 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
113 |
114 |
115 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
116 |
117 |
--------------------------------------------------------------------------------
/PeanutButter.Toasts/ToastNotification.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using System.Windows;
7 | using System.Windows.Controls;
8 | using System.Windows.Controls.Primitives;
9 | using System.Windows.Data;
10 | using System.Windows.Documents;
11 | using System.Windows.Input;
12 | using System.Windows.Media;
13 | using System.Windows.Media.Animation;
14 | using System.Windows.Media.Imaging;
15 | using System.Windows.Navigation;
16 | using System.Windows.Shapes;
17 |
18 | namespace PeanutButter.Toast
19 | {
20 | [TemplatePart(Name = "PART_DismissButton", Type = typeof(Button))]
21 | public class ToastNotification : ContentControl
22 | {
23 | public event EventHandler Dismissed;
24 |
25 | public string Title
26 | {
27 | get { return (string)GetValue(TitleProperty); }
28 | set { SetValue(TitleProperty, value); }
29 | }
30 |
31 | public static readonly DependencyProperty TitleProperty =
32 | DependencyProperty.Register("Title", typeof(string), typeof(ToastNotification));
33 |
34 | public string Message
35 | {
36 | get { return (string)GetValue(MessageProperty); }
37 | set { SetValue(MessageProperty, value); }
38 | }
39 |
40 | public static readonly DependencyProperty MessageProperty =
41 | DependencyProperty.Register("Message", typeof(string), typeof(ToastNotification));
42 |
43 | public ToastTypes ToastType
44 | {
45 | get { return (ToastTypes)GetValue(ToastTypeProperty); }
46 | set { SetValue(ToastTypeProperty, value); }
47 | }
48 |
49 | public static readonly DependencyProperty ToastTypeProperty =
50 | DependencyProperty.Register("ToastType", typeof(ToastTypes), typeof(ToastNotification), new PropertyMetadata(new PropertyChangedCallback(OnToastTypeChanged)));
51 |
52 | private static void OnToastTypeChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
53 | {
54 | ToastNotification toast = (ToastNotification)d;
55 |
56 | toast.RefreshBackgroundColour();
57 | }
58 |
59 | private void RefreshBackgroundColour()
60 | {
61 | switch (ToastType)
62 | {
63 | case ToastTypes.Success:
64 | Background = ColourSuccess;
65 | break;
66 | case ToastTypes.Error:
67 | Background = ColourDanger;
68 | break;
69 | case ToastTypes.Info:
70 | Background = ColourInfo;
71 | break;
72 | case ToastTypes.Warning:
73 | Background = ColourWarning;
74 | break;
75 | }
76 | }
77 |
78 | public bool IsPersistent
79 | {
80 | get { return (bool)GetValue(IsPersistentProperty); }
81 | set { SetValue(IsPersistentProperty, value); }
82 | }
83 |
84 | public static readonly DependencyProperty IsPersistentProperty =
85 | DependencyProperty.Register("IsPersistent", typeof(bool), typeof(ToastNotification));
86 |
87 | public double FontSizeTitle
88 | {
89 | get { return (double)GetValue(FontSizeTitleProperty); }
90 | set { SetValue(FontSizeTitleProperty, value); }
91 | }
92 |
93 | public static readonly DependencyProperty FontSizeTitleProperty =
94 | DependencyProperty.Register("FontSizeTitle", typeof(double), typeof(ToastNotification));
95 |
96 | public Brush ColourSuccess
97 | {
98 | get { return (Brush)GetValue(ColourSuccessProperty); }
99 | set { SetValue(ColourSuccessProperty, value); }
100 | }
101 |
102 | public static readonly DependencyProperty ColourSuccessProperty =
103 | DependencyProperty.Register("ColourSuccess", typeof(Brush), typeof(ToastNotification));
104 |
105 | public Brush ColourDanger
106 | {
107 | get { return (Brush)GetValue(ColourDangerProperty); }
108 | set { SetValue(ColourDangerProperty, value); }
109 | }
110 |
111 | public static readonly DependencyProperty ColourDangerProperty =
112 | DependencyProperty.Register("ColourDanger", typeof(Brush), typeof(ToastNotification));
113 |
114 | public Brush ColourInfo
115 | {
116 | get { return (Brush)GetValue(ColourInfoProperty); }
117 | set { SetValue(ColourInfoProperty, value); }
118 | }
119 |
120 | public static readonly DependencyProperty ColourInfoProperty =
121 | DependencyProperty.Register("ColourInfo", typeof(Brush), typeof(ToastNotification));
122 |
123 | public Brush ColourWarning
124 | {
125 | get { return (Brush)GetValue(ColourWarningProperty); }
126 | set { SetValue(ColourWarningProperty, value); }
127 | }
128 |
129 | public static readonly DependencyProperty ColourWarningProperty =
130 | DependencyProperty.Register("ColourWarning", typeof(Brush), typeof(ToastNotification));
131 |
132 | static ToastNotification()
133 | {
134 | DefaultStyleKeyProperty.OverrideMetadata(typeof(ToastNotification), new FrameworkPropertyMetadata(typeof(ToastNotification)));
135 | }
136 |
137 | public ToastNotification()
138 | {
139 | this.Loaded += ToastNotification_Loaded;
140 | }
141 |
142 | private void ToastNotification_Loaded(object sender, RoutedEventArgs e)
143 | {
144 | Storyboard sb = this.FindResource("ToastScaleInStoryboard") as Storyboard;
145 | Storyboard.SetTarget(sb, this);
146 | sb.Begin();
147 | }
148 |
149 | public override void OnApplyTemplate()
150 | {
151 | ButtonBase PART_DismissButton = this.GetTemplateChild("PART_DismissButton") as ButtonBase;
152 |
153 | if (PART_DismissButton != null)
154 | PART_DismissButton.Click += OnDismissed;
155 |
156 | base.OnApplyTemplate();
157 |
158 | RefreshBackgroundColour();
159 | }
160 |
161 | protected void OnDismissed(object sender, RoutedEventArgs e)
162 | {
163 | var eh = Dismissed;
164 |
165 | if (eh != null)
166 | eh(this, EventArgs.Empty);
167 | }
168 | }
169 | }
170 |
--------------------------------------------------------------------------------
/PeanutButter.Toasts/Themes/Generic.xaml:
--------------------------------------------------------------------------------
1 |
5 | #3fb618
6 | #9954bb
7 | #ff7518
8 | #ff0039
9 |
10 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
--------------------------------------------------------------------------------