Cannot launch notification from ViewModel
See original GitHub issueSynopsis
This may be related to #1 , but I am having issues with getting a notification to launch using an MVVM pattern. Relevant code is below; if you’d like to take a look at the application yourself, please feel free to clone from here - if you run into any issues getting the application to start, let me know, you may need to work some magic to get the application to run in Visual Studio.
View (/View/UI/DevWindow.xaml)
...
<!--Namespace/DataContext declaration-->
xmlns:Notifications="clr-namespace:Enterwell.Clients.Wpf.Notifications.Controls;assembly=Enterwell.Clients.Wpf.Notifications"
DataContext="{Binding Main, Source={StaticResource Locator}}"
...
<!--NotificationMessageContainer is placed within a Grid-->
<Notifications:NotificationMessageContainer
Background="{DynamicResource WindowBackgroundBrush}"
Foreground="{DynamicResource LabelTextBrush}"
Manager="{Binding NotificationMessageManager}" />
...
ViewModel (/ViewModel/MainViewModel.cs)
// Instantiate NotificationMessageManager, which the View is bound to above
public INotificationMessageManager NotificationMessageManager { get; } = new NotificationMessageManager();
...
// Create the message in the constructor
public MainViewModel()
{
try
{
NotificationMessageManager.CreateMessage()
.Accent("#1751C3")
.Animates(true)
.AnimationInDuration(0.75)
.AnimationOutDuration(2)
.HasBadge("Info")
.HasMessage("Please ingest the latest STIG Compilation Library on the settings page.")
.Dismiss().WithButton("Dismiss", button => { })
.Queue();
}
catch (Exception exception)
{
log.Error(string.Format("Unable to instantiate MainViewModel."));
log.Debug("Exception details:", exception);
}
}
...
Debugging
Running through a quick debug, NotificationMessageManager
is properly instantiated and the message is created and associated to it. Similarly, looking at the visual tree, the NotificationMessageContainer
exists, but is empty. Finally, no error messages are generated and logged, and my output window isn’t throwing anything concerning this control, so I have nothing to suggest that anything is failing.
Thanks in advance! I love the way this looks, so I am really hoping to be able to utilize the control. However, I am following a strict “no code behind” policy, which I would rather not violate.
Issue Analytics
- State:
- Created 5 years ago
- Comments:9 (9 by maintainers)
Top GitHub Comments
Eureka! That was it! My updated code:
View
ViewModel
Hopefully this approach helps you when you decide to refactor your application 😉 Thank you for the help!!!
@AleksandarDev GitHub treats the wiki just like any other source - you can clone it and submit updates / PRs via git, which would then have to be reviewed / approved before they are accepted.