Giter Site home page Giter Site logo

rafallopatka / toastnotifications Goto Github PK

View Code? Open in Web Editor NEW
687.0 31.0 167.0 2.05 MB

Toast notifications for WPF allows you to create and display rich notifications in WPF applications. It's highly configurable with set of built-in options like positions, behaviours, themes and many others. It's extendable, it gives you possibility to create custom and interactive notifications in simply manner.

License: GNU Lesser General Public License v3.0

C# 99.50% PowerShell 0.50%
notifications toast-notifications wpf xaml nuget ui-components ui messages toasts popups

toastnotifications's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

toastnotifications's Issues

Crashed the mouse enter to notification

The application crashed when the notification does not contain Border control as top level control and user move mouse to notification.
Relation: NotificationDisplayPart.OnMouseEnter.

OnMouseEnter on Custom Dialog Error

The same code works on 2.1.3, but on 2.2 it throws this exception when I move my mouse over the custom message to respond.

Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object.
at ToastNotifications.Core.NotificationDisplayPart.OnMouseEnter(MouseEventArgs e)
at System.Windows.UIElement.OnMouseEnterThunk(Object sender, MouseEventArgs e)
at System.Windows.Input.MouseEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
at System.Windows.UIElement.RaiseEvent(RoutedEventArgs e)
at System.Windows.MouseOverProperty.FireNotifications(UIElement uie, ContentElement ce, UIElement3D uie3D, Boolean oldValue)
at System.Windows.ReverseInheritProperty.FirePropThe thread 0x4044 has exited with code 0 (0x0).

.Net 4.5 Compatibility

Error Could not install package 'ToastNotifications 2.1.0'. You are trying to install this package into a project that targets '.NETFramework,Version=v4.5', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.

Strange Error in Show Information Message

Very interesting - I get:

'M0,1.2857L3.5715,4.5 0,7.7143 1.4287,9 5,5.7857 8.5713,9 10,7.7143 6.4285,4.5 10,1.2857 8.5713,0 5,3.2143 1.4287,0 0,1.2857z' is not a valid value for property 'Visual'.

This is in a highly abstracted Prism-based WPF project. It works when all of the code is loaded explicitly, however when I dynamically pull this in I get the following.

Stack Trace:

at System.Windows.Markup.WpfXamlLoader.Load(XamlReader xamlReader, IXamlObjectWriterFactory writerFactory, Boolean skipJournaledProperties, Object rootObject, XamlObjectWriterSettings settings, Uri baseUri)
at System.Windows.Markup.WpfXamlLoader.LoadBaml(XamlReader xamlReader, Boolean skipJournaledProperties, Object rootObject, XamlAccessLevel accessLevel, Uri baseUri)
at System.Windows.Markup.XamlReader.LoadBaml(Stream stream, ParserContext parserContext, Object parent, Boolean closeStream)
at System.Windows.Application.LoadComponent(Object component, Uri resourceLocator)
at ToastNotifications.Messages.Information.InformationDisplayPart.InitializeComponent()
at ToastNotifications.Messages.Information.InformationMessage.CreateDisplayPart()
at ToastNotifications.Messages.Core.MessageBase1.Configure() at ToastNotifications.Messages.Core.MessageBase1.get_DisplayPart()
at ToastNotifications.Display.NotificationsDisplaySupervisor.ShowNotification(INotification notification)
at ToastNotifications.Display.NotificationsDisplaySupervisor.InternalDisplayNotification(INotification notification)
at ToastNotifications.Display.NotificationsDisplaySupervisor.<>c__DisplayClass7_0.b__0()
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)

Clarification: does it support notifications outside main window?

Hello

me and my team are looking for a toaster notification library in WPF and came through your library. Thanks for sharing it.

One question though: does it support showing notification in main screen/desktop, so outside of main application window? Potentially also when application is running but main window is minimized, ot application runs from the "system tray"?

Something along the lines of this other library we found, where you can set position to be PrimaryScreenXxxYyy or ApplicationXxxYyy.

Thanks

Specify notification timeout

I would like to be able to specify the amount of time a toast notification appears for. Change it to 10 seconds for example, or have a toast notification that simply doesn't go away until dismissed by the user. Is that possible?

Thank you

Sign the assembly

Please sign the assembly so it can be referenced by other strongly named projects

Close Toast after some task

Hello, how can I close a toast after some task? For example, I'm showing a toasting with the info "Adding data to server", after adding the data, I would like to close the Toast. I'm using MVVM in my project. Sorry for posting this here, but I did not find any other place to find info about it. Thanks!

Option to change font size

First of all, Great plugin. Thank You.
Issue: On tablets it's harder to read message on the toast. So can you add a option increase font size?

keyboard input is not possible.

Good morning.
We are creating a hybrid app using HTML.
I need the Notification function in my app, so I am developing it as Custom Notification provided by the library.

I added CEFSharp's WebView in Custom Notification.xaml, and it loads an HTML page.
There is a text input in the HTML page, but keyboard input is not possible.
I want to know what the cause is. Is there a way to fix it?

Toast appears outside of the main Windows

Hi !

I tried to implement your solution using the upper right disposition but when the toast shows up it appears outside the Windows. If I reduce my app and move drag it around on my desktop the toast also move but with a different speed than the app.

Here's the view in which I'm trying to add the toast :

<!-- Main grid-->
<Grid x:Name="MainGrid" Background="{DynamicResource GeneralBackgroundColor}" HorizontalAlignment="Stretch" >
    <Grid.RowDefinitions>
        <RowDefinition Height="50" x:Name="HeaderBar" />
        <RowDefinition Height="*" />
    </Grid.RowDefinitions>
    <toastNotifications:NotificationTray Grid.Row="1" SnapsToDevicePixels="True" NotificationsSource="{Binding NotificationSource}" VerticalAlignment="Top" HorizontalAlignment="Right" Panel.ZIndex="1000"  />

    <!--Upper menu-->
    <Grid x:Name="Grid_TopMenu" Grid.Row="0">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="auto" />
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>
        <StackPanel x:Name="MainBarHorizontal" Orientation="Horizontal" Grid.Column="0" Background="{DynamicResource TopMenuBackGroundColor}">
            <Border BorderThickness="0" Background="{DynamicResource LeftMenuBackgroundColor}" >

            </Border>
        </StackPanel>
        <DockPanel LastChildFill="True" Grid.Column="1" Background="{DynamicResource TopMenuBackGroundColor}">
            <views:LoginControl DockPanel.Dock="Right" />
                         </DockPanel>
    </Grid>

    <!-- Left menu-->
    <Grid x:Name="Grid_Content" Grid.Row="1" Panel.ZIndex="0">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="auto" x:Name="LeftMenuColumn"/>
            <ColumnDefinition x:Name="ContentColumn"/>
        </Grid.ColumnDefinitions>

        <local:CustomListBox IsExtended="False" x:Name="LeftMenu" ItemsSource="{Binding MenuItems}" Grid.Column="0" Width="50" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" Template="{StaticResource ListBoxControlTemplate}" ItemTemplate="{StaticResource MenuItemDataTemplate}" SelectedItem="{Binding SelectedMenuItem}">
        </local:CustomListBox>

        <!-- contains all sub views -->
        <Border Grid.Column="1" x:Name="Content" Background="{DynamicResource GeneralBackgroundColor}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Panel.ZIndex="0">
            <ContentControl Content="{Binding Content}"/>
        </Border>
    </Grid>
</Grid>

notifier.ClearMessages(); not clearing the notifications.

@raflop

Expected behaviour

on calling notifier.ClearMessages(); all the notification windows should go away.

Actual behaviour

none of the notifications are going away.

Steps to reproduce behaviour,

created a notificationManager and created instance of notifier in the constructor. calling ClearNotification which has the notifier.clearmessages();

Code to reproduce behaviour

private Notifier notifier;
public NotificationManager()
{
notifier = new Notifier(cfg =>
{
cfg.LifetimeSupervisor = new TimeAndCountBasedLifetimeSupervisor(TimeSpan.FromSeconds(5), MaximumNotificationCount.FromCount(15));
cfg.PositionProvider = new PrimaryScreenPositionProvider(Corner.BottomRight, 10, 10);
cfg.DisplayOptions.Width = 400;
cfg.DisplayOptions.TopMost = true;
cfg.Dispatcher = Application.Current.Dispatcher;
});

    }

public void ClearNotification()
{
notifier.ClearMessages();
}

Questions

NullRef exception when window has never been maximized

This is close to issue #13 . In that case, the "main content window" had been maximized and then minimized at least once previously, before actually trying to show a toast.

In this case instead, main content windows has never been maximized since application start. When program logic decides a toast should be generated, another (different) NullReferenceException is thrown. Again, the toast seems to be created because Windows 10 shows its system notification with toast message. The exception is actually thrown a couple of seconds right after that.

From a debug version of DLL, we got this is the offending line, nr 94 in NotificationsSource.cs:

n.InvokeHideAnimation();

where InvokeHideAnimation Action field is null.

NullReferenceException when explicitly calling Close() on a Notification which has not yet been shown

Hi,

I have a usecase, where i replace a Notification by another when the old is still shown and a status changes. To replace the notification I explicitly call Close() on the old Notification.

There is a second usecase where more about 15 Notifications are shown, leaving 5 Notifications hidden.

Now its possible, that a new Notification should replace one of the 5 hidden notifications. Since it has never been shown, its Bind() has never been called, and the _closeAction in NotificationBase is still null.

Long story short:
The NullReferenceException happens in NotificationBase:33, at the call _closeAction.Invoke(this); when I call Close() before Bind() has been called.

Edit:
I can workaround the Exception by checking if the Id of the notification is still 0. However, the notification will of course be shown (which is what I was trying to prevent).

NullRef exception when window is closed

Hi there.
I think we met this issue also before the recent changes, but only now were able to grab some more details. We incurred in a NullReferenceException coming from the library code, and it seems we are able to repeat the process in our custom desktop app.

Our desktop app starts minimized in system tray, and then its main content window can be maximized/minimized from there. With this type of applications, you can have the "main window" (so to say) minimized, but the application still running.

For us, NotificationTray sits in that main content window, as it should be (it does not make sense to place it in the XAML for the System Tray control). When the main content window is minimized and for some reason a toast has to be shown, the exception comes up.

Here's the stacktrace (from release build I guess, there are no line numbers):

in ToastNotifications.NotificationPopup.IsOpenChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs eventArgs)
in System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
in System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
in System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)
in System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType)
in System.Windows.DependencyObject.InvalidateProperty(DependencyProperty dp, Boolean preserveCurrentValue)
in System.Windows.Data.BindingExpressionBase.Invalidate(Boolean isASubPropertyChange)
in System.Windows.Data.BindingExpression.TransferValue(Object newValue, Boolean isASubPropertyChange)
in System.Windows.Data.BindingExpression.ScheduleTransfer(Boolean isASubPropertyChange)
in MS.Internal.Data.ClrBindingWorker.NewValueAvailable(Boolean dependencySourcesChanged, Boolean initialValue, Boolean isASubPropertyChange)
in MS.Internal.Data.PropertyPathWorker.UpdateSourceValueState(Int32 k, ICollectionView collectionView, Object newValue, Boolean isASubPropertyChange)
in MS.Internal.Data.ClrBindingWorker.OnSourcePropertyChanged(Object o, String propName)
in MS.Internal.Data.PropertyPathWorker.OnPropertyChanged(Object sender, PropertyChangedEventArgs e)
in System.Windows.WeakEventManager.ListenerList`1.DeliverEvent(Object sender, EventArgs e, Type managerType)
in System.ComponentModel.PropertyChangedEventManager.OnPropertyChanged(Object sender, PropertyChangedEventArgs args)
in ToastNotifications.NotificationsSource.OnPropertyChanged(String propertyName)
in ToastNotifications.NotificationsSource.set_IsOpen(Boolean value)
in ToastNotifications.NotificationsSource.Show(String message, NotificationType type)
in OurCustomApp.Shared.ToastService.OurCustomApp.Shared.IToastService.Show(String , NotificationType )
in OurCustomApp.MainPanel.MainPanelViewModel.ReportUserMessage(UserMessage userMessage) in C:\OurCustomAppProject\MainPanel\MainPanelViewModel.cs:riga 122
in System.Reactive.AnonymousSafeObserver`1.OnNext(T value)
in System.Reactive.ScheduledObserver`1.Run(Object state, Action`1 recurse)

We'll try to grab a development copy of the DLL, so to see line numbers as well.

.NET 4.0 compatibility

Hey there! I love your work on this project. Is there any support for toast notifications V2 for a wpf app running on .net 4.0? I tried downgrading to toast notifications V1 but the position provider to show on top of the parent window is the functionality I'm primary looking for. I have a wpf app that runs in the background and hidden and 4.5 can run this with the pop ups top right of the windows screen and V1, I can only show them in the window of the wpf app.

Is it possible to bind click handlers?

I like the simplicity using this project, but am missing one feature.
I would like to bind event handlers, for example MouseLeftButtonDown when clicking a Notification.

Is this possible today?
(I've had no success so far, I can bind the events, but they never trigger)

Adding links into toast

Hi.
Thanks for this wonderful plugin!

Is it possible to add links or any XAML code inside the toast?

Thanks.
Giulio

Wobbly cards during animations

Hi there

while trying out the library in our team, we met a visual issue shown here below:

basic-example-wobbly

That is just the BasicUsageExample running from VS2013 with following changes:

<!-- MainWindow.xaml -->
<Window ... xmlns:toast="clr-namespace:ToastNotifications;assembly=ToastNotifications">
...
        <toast:NotificationTray NotificationsSource="{Binding NotificationSource}"
                                PopupFlowDirection="RightDown"  VerticalAlignment="Bottom" HorizontalAlignment="Right" />

Especially when fading out, the stack somehow wobbles, apparently because the bottom card changes height, and whole stack jumps up and down a little bit.

During execution, upon generating the first notification, the following message shows up in Immediate window console, not sure if that can be useful:

System.Windows.Data Error: 2 : Cannot find governing FrameworkElement or FrameworkContentElement for target element. BindingExpression:Path=Icon; DataItem=null; target element is 'VisualBrush' (HashCode=47097466); target property is 'Visual' (type 'Visual')

Edit: after some investigation: the issue disappears if you disable all animations and transform (maybe obvious). Also, it is present when PopupFlowDirection="RightDown" VerticalAlignment="Bottom", while not present when PopupFlowDirection="RightUp" VerticalAlignment="Top". I guess this switch might be related to the issue

For some reason, in our actual application the effect is even more visible:

application-toast-wobbly

And there two more observations there:

  1. When showing a notification starting from an empty stack (whether it's the absolute first one, or it's the first after all previous faded out), that first notification sits a little bit offscreen to the right. That is until a second notification is added: at that point, the first one proceeds moving to the left and then scrolls up. Edit: if it might help, this effects disappears when you completely disable ScaleX transform & animations
  2. If text is larger than card size, the text is clipped. How to make card larger, or adapt its size to content?

Thanks for your time

Crash outside Visual Studio

Hi,
I add simple notifications to my program and if i run it in Visual Studio it works fine. But if i run same exe file that runs VS from file explorer and run notifications, app crashes without error messege or some exception. I download sample project and it works fine, so i copy samle in my project but it crashes anyway. I would appreciate any help.
Thank you.
Petr

EDIT: Okay, i figure out that if i use PrimaryScreenPositionProvider it is okay, but if i use WindowPositionProvider it crashes.

IPositionProvider.UpdatePositionRequested event doesn't do what I expect

I am trying to make a SystemTrayPositionProvider (implementation of IPositionProvider) which follows the system tray when it's moved.

I got quite far: I get the right information and I could supply the "correct" coordinates.

But I noticed that when I handle the movement of the task bar and call the UpdatePositionRequested event, GetPosition is called but EjectDirection and also GetHeight are not queried. The toast itself doesn't move, but window where it's contained (??) does... this makes the toast stay near it's original location.

This causes issues when the task bar moves from one screen to another, or moved from bottom to top.

Maybe I have my expectations wrong, or I missed something, so I hope you can give me some tips.

Add an option to specify the Dispatcher in the constructor.

        public NotificationsSource()
            :this(Dispatcher.CurrentDispatcher)
        {

        }

        public NotificationsSource(Dispatcher dispatcher)
        {
            NotificationMessages = new ObservableCollection<NotificationViewModel>();

            MaximumNotificationCount = 5;
            NotificationLifeTime = TimeSpan.FromSeconds(6);

            _timer = new DispatcherTimer(DispatcherPriority.Normal, dispatcher);
            _timer.Interval = TimeSpan.FromMilliseconds(200);
        }

i.e.
new NotificationsSource(Application.Current.Dispatcher)

Crash when remote connexion to another computer

Hi,
first of all, thanks for your work !

i've an issue when i connect to a remote computer, which is already running an application which shows some notifications (a few per seconde for the test).
So application is already running, showing some notification, on a computer (Windows 8) with 2 screens, and when i connect from my windows 8 computer (with the standard window remote connexion), the application crashes, as you can see it here :
crash_notification

if i launch the application when connected to the remote computer, no problem, all is ok, crash happen when the program is already running before i connect to remote computer...

here is how i initialize the notifier :
m_notifier = new Notifier(cfg =>
{
cfg.PositionProvider = new WindowPositionProvider(
parentWindow: Application.Current.MainWindow,
corner: Corner.BottomRight,
offsetX: 20,
offsetY: 40);

            cfg.LifetimeSupervisor = new TimeAndCountBasedLifetimeSupervisor(
                notificationLifetime: TimeSpan.FromSeconds(30),
                maximumNotificationCount: MaximumNotificationCount.FromCount(6));

            cfg.Dispatcher = Application.Current.Dispatcher;
        });

and here how i show the message ๐Ÿ‘
Application.Current.Dispatcher.BeginInvoke(new Action(() =>
{
try
{
switch (a_logMessage.Level)
{
case EMessageLevel.Error:
m_notifier.ShowError(l_sMessage);
break;
case EMessageLevel.Information:
m_notifier.ShowInformation(l_sMessage);
break;
case EMessageLevel.Warning:
m_notifier.ShowWarning(l_sMessage);
break;
default:
m_notifier.ShowInformation(l_sMessage);
break;
}
}
catch (Exception ex) ...

feel free to ask me some question if needed.

Thanks,

Franck

How to show notifications at first position?

I was wondering if you could configure to show new notifications always at index 0. Previous notifications should move down/up.

  • corner: Top -> insert notification at 0, previous move down
  • corner: Bottom -> insert notification at 0, previous move up

I tried to manage this by inserting the NotificationDisplayPart at 0 index -> Items.Insert(0, notification); in NotificationsItemsControl class which works, but there is no animation that moves the previous notifications smoothly up/down.
How can you achieve this?

ToastNotifications doesn't work with DPI aware applications

With Windows 10, my display is 1920x1080, DPI settings is at 125%

Your IPositionProvider gives for GetHeight 864, and for a popup GetPosition returns 1275,6;-10
(864*1,25 = 1080!!! )

My IPositionProvider gives for GetHeight 1030 (1080-taskbar height, also tried 1080) and for the popup GetPosition returns 1660,-60

With Windows 7 I have the same Display size, and the same values coming from my IPositionProvider, but everything works. (there is no DPI Awareness there)

I am guessing that if I change my DPI settings from 125% to 100%, logout & in, everything works.
As it's pretty much impossible to unaware my DPI Aware application, I will need to find a fix.
Or I will need to find another solution as ToastNotifcations.

Anyway I just wanted to create this ticket right now, so it's known to other developers.
And than we see how we continue.

NotificationsWindow should ignore window shortcuts

When you focus a notification and then enter typical window shortcuts like Windows Button + Arrow Key (move window on screen) or ALT + Spacebar (open window's contextmenu) the NotificationsWindow obeys the input and moves on the screen(s) while the main application window remains at its original position.
bug_notificationswindow

Bringing toasts to the next level?

This is just some information on how I use your library, if you do something with this is up to you.

As soon as I use an UI, I am all about MVVM and also dependency injection (DI). For MVVM I use CaliburnMicro, but any other project is fine too. And for the dependency injection I use MEF (which comes with the .NET Framework) but this is also just a matter of taste.

MVVM and DI makes it possible to separate UI (View) and business logic (ViewModel) in a clean way, and although sometimes you need to invest a bit more time, you get it back later. A lot of times things get very easy.

Using ToastNotications in a MVVM & DI world was slightly tricky, it seems to work but feels a bit awkward.

What is important in MVVM, especially CaliburnMicro, is that due to the separation of the ViewModel and the View it needs life-cycle management. This prevents that the View is gone, but the ViewModel doesn't know this. This has some added advantages if you want to keep your code clean, e.g. hook up / create stuff in the activation and clean them up in the deactivation. As all the views and viewmodels are created via the framework, you can use DI everywhere and have a separation of concerns.

Crash using into usercontrol

I tried to make simple use into user control like follow code, it crash

Notifier notifier = new Notifier(cfg =>
{
cfg.PositionProvider = new PrimaryScreenPositionProvider(
corner: Corner.TopRight,
offsetX: 10,
offsetY: 10);

    cfg.LifetimeSupervisor = new TimeAndCountBasedLifetimeSupervisor(
        notificationLifetime: TimeSpan.FromSeconds(3),
        maximumNotificationCount: MaximumNotificationCount.FromCount(5));

    cfg.Dispatcher = Dispatcher.CurrentDispatcher;
  });
  notifier.ShowInformation("CIAO");

Null ref exception when toast is animated and windows is closed

Hi there

in our desktop application the following scenario is possible:

  1. application is only visible as system tray icon
  2. a window is opened from system tray menu
  3. some event happens and a notification is shown
  4. notification starts animating (e.g. getting smaller) so to disappear
  5. window is closed while animation is still going

At that point application gets an uncaught NullReference exception. This is the full log:

System.NullReferenceException: Riferimento a un oggetto non impostato su un'istanza di oggetto.
   in ToastNotifications.NotificationPopup.UpdateBounds()
   in ToastNotifications.NotificationTray.NotificationControl_OnNotificationClosing(Object sender, RoutedEventArgs e)
   in System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
   in System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
   in System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
   in System.Windows.UIElement.RaiseEvent(RoutedEventArgs e)
   in ToastNotifications.NotificationControl.InvokeHideAnimation()
   in ToastNotifications.NotificationsSource.Hide(Guid id)
   in ToastNotifications.NotificationsSource.TimerOnTick(Object sender, EventArgs eventArgs)
   in System.Windows.Threading.DispatcherTimer.FireTick(Object unused)
   in System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   in System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)

Current installed package version is 1.4.3. Not sure which source code corresponds to that version, there seems to be no tag here in Github. Looking at most recent code:

        public void UpdateBounds()
        {
            _window.UpdateBounds();
        }

the reason seems to be because _window is null.

Notification Stay on screen until User confirmation

Hi there,

Is there a way to create a notification that will stay on the screen using PrimaryScreenPositionProvider, with a Confirmation button "Ok".

this notification will not close and will be "sticky" E.g if other notifications pop up while this notification is open it will still remain on screen.

the only way to close this Notificaiton is to press the "ok" button?

Dispatcher window appears in ALT+TAB

I am using this package in a background process that occasionally pops up notifications.
Whenever the dispatcher is invoked it creates an entry in the ALT+TAB list which is persistent, if this invisible window is closed, the application will crash with an InvalidOperationException on the next attempt to create a pop up.

This mightbe resolved by having the dispatcher utilize WS_EX_TOOLWINDOW as described here (https://stackoverflow.com/questions/357076/best-way-to-hide-a-window-from-the-alt-tab-program-switcher).

Also, is it possible to use a notifier within using() to automatically dispose?
when I attempt this I either cannot create the required NotifierConfiguration, or the popup simply does not appear and I get a NullReferenceException, I guess from invalid disposal.

FreezeOnMouseEnter option turn off closing notification

Proposal.
Actual: The FreezeOnMouseEnter option turn off closing after mouse leave the notification control.
Notification never closed by timer.
Expected: the notification control will close after mouse leave the control and the time to closing of notification has been finished.
the notification control stay opened when mouse is over.

Problem with PrimaryScreenPositionProvider

Hi;

This library is amazing it does just what I want.
I've encountered a issue: when I use PrimaryScreenPositionProvider in a Notifier; my main apllication never exit. It's seem like all notification wincreated are still alive even if they fade away.

Can you please help

Notifications are not visible

Greetings, I was trying to use your project to display some notifications and I was faced with this problem...

I followed your tutorial to create custom notifications, and at the beginning I tought it wasn't working. Yet, after testing better I noticed it was working, yet the notifications where not visible.

I confimed this using the Visual Studio 'Live Tree Preview'. The NotificationWindow is created and the "CustomDisplayParts" (like in the tutorial) with the size defined in the xaml.

Yet... Nothing is shown.

I've followed your "Create Custom Notification" guide, and nothing should be different.

Also, I've downloaded the sample projects and they seem to be working fine (with special mention to the CustomNotificationsExample, the one closer to what I am trying to)

Thank you for your time.

Edit 1: Ok, after going around a little, I noticed the issue might be due to the "InitializeComponent()" at the CustomDisplayPart code-behind. I had it commented, but when I uncomment, it says it doesn't exist.

The x:Class of the xaml is correct and the build action property is set to "Page". I'll leave my xaml here:

CustomDisplayPart.txt

CustomDisplayPart(code-behind).txt

I created updates

This is nice library.
I modified it:

  • support .net framework 4
  • add ClearMessages method (all or some message). It allow clear all visible messages, or disable duplicity of notifications - hiding old notification before show new notification with the same message
  • add GetMessage() method - getting text
  • add CanClose option for single notidication - disable automatic close of it
  • add Action option for Notidfication
  • add FreezeOnMouseEnter notification option - Notification do not hide if user enter it with mouse
  • Notifications are Queued, no one is simple closed. Queued notification are show after another notification are closed / hidden
  • fixed problem with MaximumNotificationCount
  • add Tag property to MessageOptions
  • added GetOptions method
  • moved MesageOptions to Core project

Do someone want these updates, can I somewhere post them?

How can i change the size of my custom notification?

Questions

I tried to set a different Height and Width in CustomDisplayPart.xaml but my notification window is cut, such that width is the same as the "standard" notification. I want my custom notification to be bigger.
notification_screen

NullReferenceException at ToastNotifications.Lifetime.NotificationsList.Add(INotification notification)

I encountered a Critical exception when using this nuget package:

System.Transactions Critical: 0 : http://msdn.microsoft.com/TraceCodes/System/ActivityTracing/2004/07/Reliability/Exception/UnhandledUnhandled exceptionSomeApplication.exeSystem.NullReferenceException, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089Object reference not set to an instance of an object. at ToastNotifications.Lifetime.NotificationsList.Add(INotification notification)
at ToastNotifications.Lifetime.TimeAndCountBasedLifetimeSupervisor.PushNotification(INotification notification)
at ToastNotifications.Lifetime.TimeAndCountBasedLifetimeSupervisor.CloseNotification(INotification notification)
at ToastNotifications.Lifetime.TimeAndCountBasedLifetimeSupervisor.OnTimerTick()
at ToastNotifications.Utilities.Interval.&lt;&gt;c__DisplayClass3_0.&lt;Invoke&gt;b__0(Object sender, EventArgs args)
at System.Windows.Threading.DispatcherTimer.FireTick(Object unused)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
at System.Windows.Threading.DispatcherOperation.InvokeImpl()
at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state)
at MS.Internal.CulturePreservingExecutionContext.CallbackWrapper(Object obj)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at MS.Internal.CulturePreservingExecutionContext.Run(CulturePreservingExecutionContext executionContext, ContextCallback callback, Object state)
at System.Windows.Threading.DispatcherOperation.Invoke()
at System.Windows.Threading.Dispatcher.ProcessQueue()
at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean&amp; handled)
at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean&amp; handled)
at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG&amp; msg)
at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
at System.Windows.Application.RunDispatcher(Object ignore)
at System.Windows.Application.RunInternal(Window window)
at System.Windows.Application.Run(Window window)
at System.Windows.Application.Run()
at SomeApplication.App.Main()System.NullReferenceException: Object reference not set to an instance of an object.
at ToastNotifications.Lifetime.NotificationsList.Add(INotification notification)
at ToastNotifications.Lifetime.TimeAndCountBasedLifetimeSupervisor.PushNotification(INotification notification)
at ToastNotifications.Lifetime.TimeAndCountBasedLifetimeSupervisor.CloseNotification(INotification notification)
at ToastNotifications.Lifetime.TimeAndCountBasedLifetimeSupervisor.OnTimerTick()
at ToastNotifications.Utilities.Interval.&lt;&gt;c__DisplayClass3_0.&lt;Invoke&gt;b__0(Object sender, EventArgs args)
at System.Windows.Threading.DispatcherTimer.FireTick(Object unused)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
at System.Windows.Threading.DispatcherOperation.InvokeImpl()
at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state)
at MS.Internal.CulturePreservingExecutionContext.CallbackWrapper(Object obj)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at MS.Internal.CulturePreservingExecutionContext.Run(CulturePreservingExecutionContext executionContext, ContextCallback callback, Object state)
at System.Windows.Threading.DispatcherOperation.Invoke()
at System.Windows.Threading.Dispatcher.ProcessQueue()
at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean&amp; handled)
at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean&amp; handled)
at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG&amp; msg)
at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
at System.Windows.Application.RunDispatcher(Object ignore)
at System.Windows.Application.RunInternal(Window window)
at System.Windows.Application.Run(Window window)
at System.Windows.Application.Run()
at SomeApplication.App.Main()
An unhandled exception of type 'System.NullReferenceException' occurred in WindowsBase.dll
Object reference not set to an instance of an object.

Configuration:
PositionProvider = new WindowPositionProvider(Application.Current.MainWindow, Corner.BottomRight, 10, 10);
LifetimeSupervisor = new TimeAndCountBasedLifetimeSupervisor(TimeSpan.FromSeconds(1), MaximumNotificationCount.FromCount(10));
Dispatcher = Application.Current.Dispatcher;

Version:
2.2.5

Extra info:
I only used the default messages from the ToastNotifications.Messages nuget package.
i was pushing a lot of messages (around a 100 messages in a span of about 3 seconds), thats why the lifetime was set to 1 second.
Only used during debug.

RemoteAPP Issue

Expected behaviour

Notifications minimize and remain transparent
image

Actual behaviour

Notification window remains on screen after moving between monitors.

image

Steps to reproduce behaviour

Set up remote app on server(Windows Server 2012) with notifications.
Open remote app and move application between screens or make window smaller.

Code to reproduce behaviour

Questions

I haven't been able to get this to happen only through RDP. I will be trying later this evening however.

Implementation suggestion: consider using FP Option

Hi

looking randomly at code, e.g. in NotificationPopup.cs here there are several cases where a method needs to perform a lot of null checks, and return early if there's a null, or do something if it lands past the last check.

This type of code, inherently due to the way WPF controls and properties are provided, might be changed using Option types (a concept coming from Functional Programming). We recently found out a C# library porting some of those concept over to .NET, https://github.com/louthy/language-ext, and thought you might find it useful as well. BTW, we're in no way associated with that project, nor get any benefits from this.

A code like this:

private static void IsOpenChanged(DependencyObject dependencyObject,
    DependencyPropertyChangedEventArgs eventArgs)
{
    var popup = dependencyObject as NotificationPopup;
    if (popup == null)
        return;

    if (eventArgs.NewValue == eventArgs.OldValue)
        return;

    bool isOpen = (bool) eventArgs.NewValue;

    if (popup._window == null)
        return;

    if (isOpen)
        popup._window.Show();
    else
        popup._window.Hide();
}

might turn into something similar to (not checked against compiler, but just to give an idea of how it could look):

private static void IsOpenChanged(DependencyObject dependencyObject,
    DependencyPropertyChangedEventArgs eventArgs)
{
    var popupOption = new Option(dependencyObject as NotificationPopup);

    var windowOption =
      from popup in popupOption
      where (eventArgs.NewValue != eventArgs.OldValue)
      from window in popup._window;

    bool isOpen = (bool)eventArgs.NewValue;

    windowOption.Match(
      Some: window => isOpen ? window.Show() : window.Hide(), 
      None: () => { /* do nothing */ });
}

The same refactoring could be applied in other cases when there are repeated null-checks, or repeated if-error checks, or (with Either type) when there's a right possible result and a wrong one.

Stacking Notifications

Is it possible to control the Z index of several Notifiers? I have experienced that if I use more than one notifier in my application (with different settings like liftime etc.) they tend to stack on top of each other. Is there any way I can control this?

Close button shows on mouse hover

The close button starts to show on mouse hover, even though I have set the ShowCloseButton = false
This only occurs in the newest 2.2.0 version, and not in the earlier 2.1.3 version

Toast popup position changes when mahapps app fullscreen

I reproduced with the included BasicUsageExample Mahapps example by double clicking the title bar to go full screen and pressing the buttons to launch a popup. The popups appear away from the corner. I first noticed this with my own Mahapps based application with the notifications in the BottomLeft not appearing on the screen at all when my app goes full screen Mahapps style (no title bar).

Update:I'm operating with 3 screens if that is influencing the coordinates & the Release version will not build in VS2017 : error MSB3322: Unable to get MD5 checksum for the key file "../../Build/DevCrew.ToastNotifications.pfx". Could not find file 'H:\Downloads\ToastNotifications-master-v2\Build\DevCrew.ToastNotifications.pfx'

Update: Resolved the build error by deleting the entries from the project files and testing on a single monitor system still has the coordinate issue when resizing the window.

NRE sometimes (mostly when debugging app)

Sometimes I get the NullReferenceException when trying to display a toast for the first time after starting the application.

It's happening when calling _toastNotifier.ShowSuccess(msg, _msgOptions); at:

at ToastNotifications.Display.NotificationsItemsControl.PrepareItemsControl(ItemsControl itemsControl, Boolean reverse)

Some more info from call stack (from VS debugger):

ToastNotifications.dll!ToastNotifications.Display.NotificationsItemsControl.PrepareItemsControl(System.Windows.Controls.ItemsControl itemsControl = {ToastNotifications.Display.NotificationsItemsControl}, bool reverse = true)
ToastNotifications.dll!ToastNotifications.Display.NotificationsItemsControl.ShouldReverseItemsPropertyChanged(System.Windows.DependencyObject d = {ToastNotifications.Display.NotificationsItemsControl}, System.Windows.DependencyPropertyChangedEventArgs e = {System.Windows.DependencyPropertyChangedEventArgs})
WindowsBase.dll!System.Windows.DependencyObject.OnPropertyChanged(System.Windows.DependencyPropertyChangedEventArgs e)
PresentationFramework.dll!System.Windows.FrameworkElement.OnPropertyChanged(System.Windows.DependencyPropertyChangedEventArgs e)
WindowsBase.dll!System.Windows.DependencyObject.NotifyPropertyChange(System.Windows.DependencyPropertyChangedEventArgs args)
WindowsBase.dll!System.Windows.DependencyObject.UpdateEffectiveValue(System.Windows.EntryIndex entryIndex, System.Windows.DependencyProperty dp = {System.Windows.DependencyProperty}, System.Windows.PropertyMetadata metadata, System.Windows.EffectiveValueEntry oldEntry, ref System.Windows.EffectiveValueEntry newEntry = {System.Windows.EffectiveValueEntry}, bool coerceWithDeferredReference, bool coerceWithCurrentValue, System.Windows.OperationType operationType)
WindowsBase.dll!System.Windows.DependencyObject.SetValueCommon(System.Windows.DependencyProperty dp, object value, System.Windows.PropertyMetadata metadata, bool coerceWithDeferredReference, bool coerceWithCurrentValue, System.Windows.OperationType operationType, bool isInternal)
WindowsBase.dll!System.Windows.DependencyObject.SetValue(System.Windows.DependencyProperty dp, object value)
ToastNotifications.dll!ToastNotifications.Display.NotificationsItemsControl.ShouldReverseItems.set(bool value = true)
ToastNotifications.dll!ToastNotifications.Display.NotificationsWindow.SetEjectDirection(ToastNotifications.Core.EjectDirection ejectDirection = ToTop)
ToastNotifications.dll!ToastNotifications.Display.NotificationsDisplaySupervisor.UpdateEjectDirection()
ToastNotifications.dll!ToastNotifications.Display.NotificationsDisplaySupervisor.PositionProviderOnUpdateEjectDirectionRequested(object sender = {ToastNotifications.Position.WindowPositionProvider}, System.EventArgs eventArgs = {System.EventArgs})
ToastNotifications.dll!ToastNotifications.Position.WindowPositionProvider.RequestUpdatePosition()
ToastNotifications.dll!ToastNotifications.Position.WindowPositionProvider.ParentWindowOnActivated(object sender = {EasyTouch.App.View.Shell}, System.EventArgs eventArgs = {System.EventArgs})
PresentationFramework.dll!System.Windows.Window.OnActivated(System.EventArgs e)
...native/WPF... 
PresentationFramework.dll!System.Windows.Window.Show()
ToastNotifications.dll!ToastNotifications.Display.NotificationsDisplaySupervisor.ShowWindow()
ToastNotifications.dll!ToastNotifications.Display.NotificationsDisplaySupervisor.InternalDisplayNotification(ToastNotifications.Core.INotification notification = {ToastNotifications.Messages.Success.SuccessMessage})
ToastNotifications.dll!ToastNotifications.Display.NotificationsDisplaySupervisor.DisplayNotification.AnonymousMethod__0()
...native/WPF... 
ToastNotifications.dll!ToastNotifications.Display.NotificationsDisplaySupervisor.Dispatch(System.Action action = {Method = {System.Reflection.RuntimeMethodInfo}})
ToastNotifications.dll!ToastNotifications.Display.NotificationsDisplaySupervisor.DisplayNotification(ToastNotifications.Core.INotification notification = {ToastNotifications.Messages.Success.SuccessMessage})	
ToastNotifications.dll!ToastNotifications.Display.NotificationsDisplaySupervisor.LifetimeSupervisorOnShowNotificationRequested(object sender = {ToastNotifications.Lifetime.TimeAndCountBasedLifetimeSupervisor}, ToastNotifications.Lifetime.ShowNotificationEventArgs eventArgs = {ToastNotifications.Lifetime.ShowNotificationEventArgs})
ToastNotifications.dll!ToastNotifications.Lifetime.TimeAndCountBasedLifetimeSupervisor.RequestShowNotification(ToastNotifications.Lifetime.ShowNotificationEventArgs e = {ToastNotifications.Lifetime.ShowNotificationEventArgs})
ToastNotifications.dll!ToastNotifications.Lifetime.TimeAndCountBasedLifetimeSupervisor.PushNotification(ToastNotifications.Core.INotification notification = {ToastNotifications.Messages.Success.SuccessMessage})
ToastNotifications.dll!ToastNotifications.Notifier.Notify<ToastNotifications.Messages.Success.SuccessMessage>(System.Func<ToastNotifications.Core.INotification> createNotificationFunc = {Method = {System.Reflection.RuntimeMethodInfo}})
ToastNotifications.Messages.dll!ToastNotifications.Messages.SuccessExtensions.ShowSuccess(ToastNotifications.Notifier notifier = {ToastNotifications.Notifier}, string message = "Template Muster TT1 opened.", ToastNotifications.Core.MessageOptions displayOptions = {ToastNotifications.Core.MessageOptions})	

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.