■ DisplayInformation 클래스를 사용해 디스플레이 정보를 구하는 방법을 보여준다.
▶ MainPage.xaml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
<Page x:Class="TestProject.MainPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" FontFamily="나눔고딕코딩" FontSize="16"> <Grid> <Grid Name="grid" HorizontalAlignment="Center" VerticalAlignment="Center"> <Grid.ColumnDefinitions> <ColumnDefinition Width="Auto" /> <ColumnDefinition Width="Auto" /> </Grid.ColumnDefinitions> </Grid> </Grid> </Page> |
▶ MainPage.xaml.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 |
using Windows.Graphics.Display; using Windows.UI.Xaml; using Windows.UI.Xaml.Controls; namespace TestProject { /// <summary> /// 메인 페이지 /// </summary> public sealed partial class MainPage : Page { //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - MainPage() /// <summary> /// 생성자 /// </summary> public MainPage() { InitializeComponent(); DisplayInformation displayInformation = DisplayInformation.GetForCurrentView(); AddRow(this.grid, "CurrentOrientation" , displayInformation.CurrentOrientation ); AddRow(this.grid, "DiagonalSizeInInches" , displayInformation.DiagonalSizeInInches ); AddRow(this.grid, "LogicalDpi" , displayInformation.LogicalDpi ); AddRow(this.grid, "NativeOrientation" , displayInformation.NativeOrientation ); AddRow(this.grid, "RawDpiX" , displayInformation.RawDpiX ); AddRow(this.grid, "RawDpiY" , displayInformation.RawDpiY ); AddRow(this.grid, "RawPixelsPerViewPixel" , displayInformation.RawPixelsPerViewPixel ); AddRow(this.grid, "ResolutionScale" , displayInformation.ResolutionScale ); AddRow(this.grid, "ScreenHeightInRawPixels", displayInformation.ScreenHeightInRawPixels); AddRow(this.grid, "ScreenWidthInRawPixels" , displayInformation.ScreenWidthInRawPixels ); AddRow(this.grid, "StereoEnabled" , displayInformation.StereoEnabled ); } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Private #region 행 추가하기 - AddRow(grid, caption, value) /// <summary> /// 행 추가하기 /// </summary> /// <param name="grid">그리드</param> /// <param name="caption">제목</param> /// <param name="value">값</param> private void AddRow(Grid grid, string caption, object value) { grid.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto }); int rowIndex = grid.RowDefinitions.Count - 1; TextBlock textBlock = new TextBlock(); textBlock.Margin = new Thickness(0, 1, 10, 1); textBlock.HorizontalAlignment = HorizontalAlignment.Right; textBlock.VerticalAlignment = VerticalAlignment.Center; textBlock.Text = caption; grid.Children.Add(textBlock); Grid.SetRow (textBlock, rowIndex); Grid.SetColumn(textBlock, 0 ); TextBox textBox = new TextBox(); textBox.Margin = new Thickness(0, 1, 0, 1); textBox.HorizontalAlignment = HorizontalAlignment.Left; textBox.VerticalAlignment = VerticalAlignment.Center; textBox.Text = value.ToString(); grid.Children.Add(textBox); Grid.SetRow (textBox, rowIndex); Grid.SetColumn(textBox, 1 ); } #endregion } } |