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

728x90
반응형
728x170

TestProject.zip
0.03MB

▶ MainPage.xaml

<Page x:Class="TestProject.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:controls="using:Microsoft.Toolkit.Uwp.UI.Controls"
    xmlns:local="using:TestProject"
    Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
    FontFamily="나눔고딕코딩"
    FontSize="16">
    <Page.Resources>
        <local:ByteToMegabyteConverter x:Key="ByteToMegabyteConverterKey" />
        <local:CPUTimeConverter x:Key="CPUTimeConverterKey" />
    </Page.Resources>
    <Grid>
        <Grid Margin="10">
            <Grid.RowDefinitions>
                <RowDefinition Height="*"    />
                <RowDefinition Height="10"   />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>
            <controls:DataGrid Name="dataGrid" Grid.Row="0"
                BorderBrush="Black"
                BorderThickness="1"
                AutoGenerateColumns="False">
                <controls:DataGrid.Columns>
                    <controls:DataGridTextColumn
                        Header="명칭"
                        Width="Auto"
                        Binding="{Binding ExecutableFileName}" />
                    <controls:DataGridTextColumn
                        Header="PID"
                        Width="Auto"
                        Binding="{Binding ProcessID}" />
                    <controls:DataGridTextColumn
                        Header="커널 시간"
                        Width="Auto"
                        Binding="{Binding KernelTime, Converter={StaticResource CPUTimeConverterKey}}" />
                    <controls:DataGridTextColumn
                        Header="사용자 시간"
                        Width="Auto"
                        Binding="{Binding UserTime, Converter={StaticResource CPUTimeConverterKey}}" />
                    <controls:DataGridTextColumn
                        Header="페이지 파일"
                        Width="Auto"
                        Binding="{Binding PageFileSize, Converter={StaticResource ByteToMegabyteConverterKey}}" />
                    <controls:DataGridTextColumn
                        Header="작업 세트"
                        Width="Auto"
                        Binding="{Binding WorkingSetSize, Converter={StaticResource ByteToMegabyteConverterKey}}" />
                    <controls:DataGridTextColumn
                        Header="디스크 읽기"
                        Width="Auto"
                        Binding="{Binding ReadByteCount, Converter={StaticResource ByteToMegabyteConverterKey}}" />
                    <controls:DataGridTextColumn
                        Header="디스크 쓰기"
                        Width="Auto"
                        Binding="{Binding WriteByteCount, Converter={StaticResource ByteToMegabyteConverterKey}}" />
                    <controls:DataGridTextColumn
                        Header="타입"
                        Width="Auto"
                        Binding="{Binding AppType}" />
                </controls:DataGrid.Columns>
            </controls:DataGrid>
            <Button Name="refreshButton" Grid.Row="2"
                HorizontalAlignment="Right"
                Width="100"
                Height="30"
                Content="갱신" />
        </Grid>
    </Grid>
</Page>

 

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 , ,

댓글을 달아 주세요