[DEVEXPRESS/WPF] NotificationService 클래스 : 토스트 알림(Toast Notification) 표시하기
DevExpress/WPF 2021. 4. 27. 19:35728x90
반응형
728x170
▶ MainWindow.xaml
<Window x:Class="TestProject.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Width="800"
Height="600"
Title="NotificationService 클래스 : 토스트 알림(Toast Notification) 표시하기"
FontFamily="나눔고딕코딩"
FontSize="16">
<Grid>
<Button Name="showToastNotificationButton"
Width="200"
Height="30"
Content="토스트 알림 표시하기" />
</Grid>
</Window>
728x90
▶ MainWindow.xaml.cs
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Media.Imaging;
using DevExpress.Data;
using DevExpress.Mvvm;
using DevExpress.Mvvm.UI;
namespace TestProject
{
/// <summary>
/// 메인 윈도우
/// </summary>
public partial class MainWindow : Window
{
//////////////////////////////////////////////////////////////////////////////////////////////////// Field
////////////////////////////////////////////////////////////////////////////////////////// Private
#region Field
/// <summary>
/// 알림 서비스
/// </summary>
private NotificationService service;
/// <summary>
/// 비트맵 이미지
/// </summary>
private BitmapImage bitmapImage;
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
////////////////////////////////////////////////////////////////////////////////////////// Public
#region 생성자 - MainWindow()
/// <summary>
/// 생성자
/// </summary>
public MainWindow()
{
InitializeComponent();
this.service = new NotificationService();
this.service.ApplicationId = "TestProject";
this.service.ApplicationName = "TestProject";
this.service.UseWin8NotificationsIfAvailable = true;
this.service.CreateApplicationShortcut = true;
this.service.PredefinedNotificationDuration = PredefinedNotificationDuration.Default;
this.service.PredefinedNotificationTemplate = NotificationTemplate.ShortHeaderAndTwoTextFields;
ShellHelper.TryCreateShortcut(this.service.ApplicationId, this.service.ApplicationName);
Uri uri = GetResourceURI(null, "IMAGE/toast.png");
this.bitmapImage = new BitmapImage(uri);
Closing += Window_Closing;
this.showToastNotificationButton.Click += showToastNotificationButton_Click;
}
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Method
////////////////////////////////////////////////////////////////////////////////////////// Private
//////////////////////////////////////////////////////////////////////////////// Event
#region 윈도우 닫을 경우 처리하기 - Window_Closing(sender, e)
/// <summary>
/// 윈도우 닫을 경우 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void Window_Closing(object sender, CancelEventArgs e)
{
ShellHelper.TryRemoveShortcut(this.service.ApplicationName);
}
#endregion
#region 토스트 알림 표시하기 버튼 클릭시 처리하기 - showToastNotificationButton_Click(sender, e)
/// <summary>
/// 토스트 알림 표시하기 버튼 클릭시 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void showToastNotificationButton_Click(object sender, RoutedEventArgs e)
{
INotification notification = this.service.CreatePredefinedNotification
(
"알림",
"등록된 사용자가 아닙니다.",
DateTime.Now.ToString(),
this.bitmapImage
);
notification.ShowAsync().ContinueWith(resultTask => ProcessToastNotificationClicked(resultTask, null));
}
#endregion
#region 토스트 알림 클릭시 처리하기 - ProcessToastNotificationClicked(resultTask, parameter)
/// <summary>
/// 토스트 알림 클릭시 처리하기
/// </summary>
/// <param name="resultTask">결과 태스크</param>
/// <param name="parameter">매개 변수</param>
private void ProcessToastNotificationClicked(Task<NotificationResult> resultTask, object parameter)
{
NotificationResult result = resultTask.Result;
switch(result)
{
case NotificationResult.Activated :
Process.Start("https://icodebroker.tistory.com");
break;
}
}
#endregion
//////////////////////////////////////////////////////////////////////////////// Function
#region 리소스 URI 구하기 - GetResourceURI(assemblyName, resourcePath)
/// <summary>
/// 리소스 URI 구하기
/// </summary>
/// <param name="assemblyName">어셈블리명</param>
/// <param name="resourcePath">리소스 경로</param>
/// <returns>리소스 URI</returns>
private Uri GetResourceURI(string assemblyName, string resourcePath)
{
if(string.IsNullOrEmpty(assemblyName))
{
return new Uri($"pack://application:,,,/{resourcePath}");
}
else
{
return new Uri($"pack://application:,,,/{assemblyName};component/{resourcePath}");
}
}
#endregion
}
}
728x90
반응형
그리드형(광고전용)
'DevExpress > WPF' 카테고리의 다른 글
[DEVEXPRESS/WPF] NotificationService 클래스 : 커스텀 토스트 알림(Toast Notification) 표시하기 (0) | 2021.04.28 |
---|---|
[DEVEXPRESS/WPF] NotificationService 클래스 : 토스트 알림(Toast Notification) 표시하기 (0) | 2021.04.27 |
[DEVEXPRESS/WPF] CameraControl 클래스 : 카메라 사용하기 (기능 개선) (0) | 2020.12.25 |
[DEVEXPRESS/WPF] GridControl 클래스 : NodeExpanding 이벤트를 사용해 동적 데이터 로딩하기 (0) | 2019.04.18 |
[DEVEXPRESS/WPF] GridControl 클래스 : CustomColumnSort 이벤트를 사용해 커스텀 데이터 정렬하기 (0) | 2019.04.18 |
[DEVEXPRESS/WPF] GridControl 클래스 : 커스텀 데이터 그룹핑 사용하기 (0) | 2019.04.18 |
[DEVEXPRESS/WPF] GridControl 클래스 : 언바운드 모드 트리 사용하기 (0) | 2019.04.18 |
[DEVEXPRESS/WPF] GridControl 클래스 : 컬럼 에디터 생성하기 (0) | 2019.04.18 |
[DEVEXPRESS/WPF] GridControl 클래스 : MASTER-DETAIL 사용하기 (0) | 2018.03.10 |
[DEVEXPRESS/WPF] GridControl 클래스 : 커스텀 데이터 정렬하기 (0) | 2018.03.10 |
[DEVEXPRESS/WPF] GridControl 클래스 : 커스텀 데이터 그룹핑 하기 (0) | 2018.03.10 |
댓글을 달아 주세요