■ ListView 클래스에서 시스템 매개 변수 값을 표시하는 방법을 보여준다.
▶ SystemParameter.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
namespace TestProject { /// <summary> /// 시스템 파라미터 /// </summary> public class SystemParamer { //////////////////////////////////////////////////////////////////////////////////////////////////// Field ////////////////////////////////////////////////////////////////////////////////////////// Private #region Field /// <summary> /// 명칭 /// </summary> private string name; /// <summary> /// 값 /// </summary> private object value; #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region 명칭 - Name /// <summary> /// 명칭 /// </summary> public string Name { set { this.name = value; } get { return this.name; } } #endregion #region 값 - Value /// <summary> /// 값 /// </summary> public object Value { set { this.value = value; } get { return this.value; } } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Public #region 문자열 구하기 - ToString() /// <summary> /// 문자열 구하기 /// </summary> /// <returns>문자열</returns> public override string ToString() { return string.Format("{0}={1}", this.name, this.value); } #endregion } } |
▶ MainWindow.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
using System; using System.ComponentModel; using System.Reflection; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Media; namespace TestProject { /// <summary> /// 메인 윈도우 /// </summary> public class MainWindow : Window { //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - MainWindow() /// <summary> /// 생성자 /// </summary> public MainWindow() { Title = "ListView 클래스 : 시스템 매개 변수 값 표시하기"; Width = 800d; Height = 600d; FontFamily = new FontFamily("나눔고딕코딩"); FontSize = 16d; ListView listView = new ListView(); Content = listView; GridView gridView = new GridView(); listView.View = gridView; GridViewColumn nameGridViewColumn = new GridViewColumn(); nameGridViewColumn.Header = "속성"; nameGridViewColumn.Width = 300; nameGridViewColumn.DisplayMemberBinding = new Binding("Name"); gridView.Columns.Add(nameGridViewColumn); GridViewColumn valueGridViewColumn = new GridViewColumn(); valueGridViewColumn.Header = "값"; valueGridViewColumn.Width = 200; valueGridViewColumn.DisplayMemberBinding = new Binding("Value"); gridView.Columns.Add(valueGridViewColumn); listView.Items.SortDescriptions.Add(new SortDescription("Name", ListSortDirection.Ascending)); PropertyInfo[] propertyInfoArray = typeof(SystemParameters).GetProperties(); foreach(PropertyInfo propertyInfo in propertyInfoArray) { if(propertyInfo.PropertyType != typeof(ResourceKey)) { SystemParamer systemParamer = new SystemParamer(); systemParamer.Name = propertyInfo.Name; systemParamer.Value = propertyInfo.GetValue(null, null); listView.Items.Add(systemParamer); } } } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Static //////////////////////////////////////////////////////////////////////////////// Private #region 프로그램 시작하기 - Main() /// <summary> /// 프로그램 시작하기 /// </summary> [STAThread] public static void Main() { Application application = new Application(); application.Run(new MainWindow()); } #endregion } } |