첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
728x90
반응형
728x170

TestSolution.zip
0.11MB

▶ 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="UWP API 사용하기"
    FontFamily="나눔고딕코딩"
    FontSize="16">
    <Grid>
        <Button Name="sendButton"
            HorizontalAlignment="Center"
            VerticalAlignment="Center"
            Width="180"
            Height="30"
            Content="토스트 메시지 보내기" />
    </Grid>
</Window>

 

728x90

 

▶ MainWindow.xaml.cs

using System;
using System.Windows;
using Windows.Data.Xml.Dom;
using Windows.UI.Notifications;

namespace TestProject
{
    /// <summary>
    /// 메인 윈도우
    /// </summary>
    public partial class MainWindow : Window
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region 생성자 - MainWindow()

        /// <summary>
        /// 생성자
        /// </summary>
        public MainWindow()
        {
            InitializeComponent();

            this.sendButton.Click += sendButton_Click;
        }

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Method
        ////////////////////////////////////////////////////////////////////////////////////////// Private

        #region 토스트 메시지 보내기 버튼 클릭시 처리하기 - sendButton_Click(sender, e)

        /// <summary>
        /// 토스트 메시지 보내기 버튼 클릭시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void sendButton_Click(object sender, RoutedEventArgs e)
        {
            string text1    = "알림";
            string text2    = $"현재 시각은 {DateTime.Now:HH:mm:ss} 입니다.";
            string imageURI = "ms-appx:///Images/sample.png";

            string xml = $@"
<toast>
    <visual>
        <binding template='ToastGeneric'>
            <image placement='appLogoOverride' src='{imageURI}'/>
            <text>{text1}</text>
            <text>{text2}</text>
            <image src='{imageURI}'/>
        </binding>
    </visual>
</toast>";

            XmlDocument document = new XmlDocument();

            document.LoadXml(xml);

            ToastNotification notification = new ToastNotification(document);

            ToastNotifier notifier = ToastNotificationManager.CreateToastNotifier();

            notifier.Show(notification);
        }

        #endregion
    }
}

 

[설정]

1. .NET Framework 버전을 사용하는 경우 [비주얼 스튜디오]에서 [도구] / [Nuget 패키지 관리자] / [패키지 관리자 설정] 메뉴를 클릭한다.

 

2. [옵션] 대화 상자에서 아래와 같이 설정한다.

 

3. 아래 누겟 패키지를 설치한다.

  • Microsoft.Windows.SDK.Contracts
  • System.Runtime.WindowsRuntime
  • System.Runtime.WindowsRuntime.UI.Xaml

 

4. [새 프로젝트 추가] 대화 상자에서 아래와 같이 [Windows 애플리케이션 패키징 프로젝트] 템플릿을 선택하고 [다음] 버튼을 클릭한다.

 

5. [새 프로젝트 구성] 대화 상자에서 아래와 같이 입력하고 [만들기] 버튼을 클릭한다.

 

6. [TestProjectSetup] 프로젝트에서 [애플리케이션] 항목에 [TestProject] 프로젝트를 추가한다.

 

7. [TestProjectSetup] 프로젝트의 [Package.appxmanifest] 파일에서 아래와 같이 설정한다.

728x90
반응형
그리드형(광고전용)
Posted by icodebroker

댓글을 달아 주세요