├── 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 | 114 | 115 | 116 | 117 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | --------------------------------------------------------------------------------