Enterwell / Wpf.Notifications

WPF notifications UI controls (as seen in VS Code)
MIT License
400 stars 40 forks source link

dont work with MVVM #1

Closed ghost1372 closed 7 years ago

ghost1372 commented 7 years ago

i have a MVVM Project when i use this.DataContext = this; my MVVM Command not work. gif

AleksandarDev commented 7 years ago

@ghost1372 I see that you get NullReferenceException with btnShowDashboard which has nothing to do with WpfNotifications package. Is that correct?

ghost1372 commented 7 years ago

yes btnShowDashboard Call a method in ViewModel if username and password is correct go to Dashboard UserControl and if incorrect send a message to LoginView for Showing Notification, if i dont write this.DataContext = this; notification dont shown and if i write this code my Command Not Execute, so is there any way to show notification without using this.DataContext = this; ???


Update: i found problem when my command want to run need --> LoginViewModel as DataContext but Notification for Show need --> LoginView as DataContext so how i can fix this problem that both of them use LoginViewModel as DataContext?

AleksandarDev commented 7 years ago

You should trigger the Notifications from your ViewModel so only ViewModel needs to be bind to DataContext. From view you can call the method of ViewModel when needed (or trigger|execute the command)

In ideal case, you would place the NotificationMessageManager instance to your DI container as Singleton, or you can instantiate the NotificationMessageManager in the ViewModel and then bind the Manager property of NotificationsContainer to that instance from ViewModel like so:

<controls:NotificationMessageContainer Manager="{Binding Manager}" />

This will then bind to the ViewModel.Manager property if you specify DataContext of View to be the ViewModel.

Take a look at Basic Usage section from our readme.

ghost1372 commented 7 years ago

tnx

AleksandarDev commented 7 years ago

Please let me know if that worked for you.

ghost1372 commented 7 years ago

i will try this