For using Toast Notifications in WPF controls, we can install the WPFNotification package using NuGet . When it is installed, it will automatically add assembly references and modify the App.xaml file for you.
The code of App.xaml is as follows:
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/WPFNotification;component/Assets/NotificationUI.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
An example of button display notification is as follows.
The code of xaml is as follows:
<Grid>
<Button Content="Button" HorizontalAlignment="Left" Margin="285,193,0,0" VerticalAlignment="Top" Width="75" Click="Button_Click"/>
</Grid>
The code of xaml.cs is as follows:
private void Button_Click(object sender, RoutedEventArgs e)
{
INotificationDialogService _dailogService = new NotificationDialogService();
var newNotification = new Notification()
{
Title = "Machine error",
Message = "Error!! Please check your Machine Code and Try Again"
};
_dailogService.ShowNotificationWindow(newNotification);
}
The result is shown in the figure: