첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
본 블로그는 광고를 포함하고 있습니다.
광고 클릭에서 발생하는 수익금은 모두 블로그 콘텐츠 향상을 위해 쓰여집니다.

728x90
반응형
728x170

TestProject.zip
0.03MB

▶ Package.appxmanifest

<?xml version="1.0" encoding="utf-8"?>
<Package
    xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10"
    xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest"
    xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10"
    xmlns:iot="http://schemas.microsoft.com/appx/manifest/iot/windows10"
    xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"
    IgnorableNamespaces="mp uap iot rescap">
    <Identity
        Name="1e3306d1-7340-4412-a1b7-e908babd8ddb"
        Publisher="CN=king"
        Version="1.0.0.0" />
    <mp:PhoneIdentity
        PhoneProductId="1e3306d1-7340-4412-a1b7-e908babd8ddb"
        PhonePublisherId="00000000-0000-0000-0000-000000000000" />
    <Properties>
        <DisplayName>TestProject</DisplayName>
        <PublisherDisplayName>king</PublisherDisplayName>
        <Logo>Assets\StoreLogo.png</Logo>
    </Properties>
    <Dependencies>
        <TargetDeviceFamily Name="Windows.Universal"
            MinVersion="10.0.0.0"
            MaxVersionTested="10.0.0.0" />
    </Dependencies>
    <Resources>
        <Resource Language="x-generate" />
    </Resources>
    <Applications>
        <Application Id="App"
            Executable="$targetnametoken$.exe"
            EntryPoint="TestProject.App">
            <uap:VisualElements
                DisplayName="AppDiagnosticInfo 클래스 : RequestAccessAsync 정적 메소드를 사용해 진단 정보에 대한 액세스 요청하기"
                Square150x150Logo="Assets\Square150x150Logo.png"
                Square44x44Logo="Assets\Square44x44Logo.png"
                Description="TestProject"
                BackgroundColor="transparent">
            <uap:DefaultTile Wide310x150Logo="Assets\Wide310x150Logo.png" />
            <uap:SplashScreen Image="Assets\SplashScreen.png" />
            </uap:VisualElements>
        </Application>
    </Applications>
    <Capabilities>
        <Capability Name="internetClient" />
        <rescap:Capability Name="appDiagnostics" />
    </Capabilities>
</Package>

 

728x90

 

▶ MainPage.xaml.cs

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using Windows.System;
using Windows.System.Diagnostics;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Media.Imaging;
using Windows.UI.Xaml.Navigation;

namespace TestProject
{
    /// <summary>
    /// 메인 페이지
    /// </summary>
    public sealed partial class MainPage : Page
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Field
        ////////////////////////////////////////////////////////////////////////////////////////// Private

        #region Field

        /// <summary>
        /// 디폴트 프로세스 이미지
        /// </summary>
        private BitmapImage defaultProcessImage;

        /// <summary>
        /// 디폴트 앱 이미지
        /// </summary>
        private BitmapImage defaultAppImage;

        /// <summary>
        /// 프로세스 컬렉션
        /// </summary>
        private ObservableCollection<ProcessModel> processCollection = new ObservableCollection<ProcessModel>();

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region 생성자 - MainPage()

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

            this.defaultProcessImage = new BitmapImage(new Uri("ms-appx:/Assets/default-process-icon.png", UriKind.Absolute));
            this.defaultAppImage     = new BitmapImage(new Uri("ms-appx:/Assets/default-app-icon.png"    , UriKind.Absolute));

            this.dataGrid.ItemsSource = this.processCollection;

            this.refreshButton.Click += refreshButton_Click;
        }

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Method
        ////////////////////////////////////////////////////////////////////////////////////////// Protected

        #region 탐색되는 경우 처리하기 - OnNavigatedTo(e)

        /// <summary>
        /// 탐색되는 경우 처리하기
        /// </summary>
        /// <param name="e">이벤트 인자</param>
        protected async override void OnNavigatedTo(NavigationEventArgs e)
        {
            await AppDiagnosticInfo.RequestAccessAsync();

            SetProcessData();

            base.OnNavigatedTo(e);
        }

        #endregion

        ////////////////////////////////////////////////////////////////////////////////////////// Private
        //////////////////////////////////////////////////////////////////////////////// Event

        #region 갱신 버튼 클릭시 처리하기 - refreshButton_Click(sender, e)

        /// <summary>
        /// 갱신 버튼 클릭시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void refreshButton_Click(object sender, RoutedEventArgs e)
        {
            SetProcessData();
        }

        #endregion

        //////////////////////////////////////////////////////////////////////////////// Function

        #region 프로세스 데이터 설정하기 - SetProcessData()

        /// <summary>
        /// 프로세스 데이터 설정하기
        /// </summary>
        private void SetProcessData()
        {
            this.processCollection.Clear();    

            IReadOnlyList<ProcessDiagnosticInfo> processDiagnosticInfoList = ProcessDiagnosticInfo.GetForProcesses();

            if(processDiagnosticInfoList != null)
            {
                foreach(ProcessDiagnosticInfo processDiagnosticInfo in processDiagnosticInfoList)
                {
                    BitmapImage bitmapImage = null;

                    if(processDiagnosticInfo.IsPackaged)
                    {
                        bitmapImage = this.defaultAppImage;
                    }
                    else
                    {
                        bitmapImage = this.defaultProcessImage;
                    }

                    ProcessModel process = new ProcessModel(processDiagnosticInfo, bitmapImage);

                    this.processCollection.Add(process);
                }
            }
        }

        #endregion
    }
}
728x90
반응형
그리드형
Posted by 사용자 icodebroker
TAG , ,

댓글을 달아 주세요