■ ResourceDictionary 엘리먼트의 Source 속성을 사용해 컨트롤 컴팩트 크기를 사용하는 방법을 보여준다.
▶ SampleCompactSizingPage.xaml
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 |
<Page x:Class="TestProject.SampleCompactSizingPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <Page.Resources> <ResourceDictionary Source="ms-appx:///Microsoft.UI.Xaml/DensityStyles/Compact.xaml" /> </Page.Resources> <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> <StackPanel Spacing="4"> <TextBlock Name="HeaderBlock" FontSize="18" Text="컴팩트 크기" /> <TextBox Name="firstNameTextBox" Header="이름 :" /> <TextBox Name="lastNameTextBox" Header="성 :" /> <PasswordBox Name="passwordPasswordBox" Header="패스워드 :" /> <PasswordBox Name="confirmPasswordPasswordBox" Header="패스워드 확인 :" /> <DatePicker Name="chosenDatePicker" Header="날짜 선택" /> </StackPanel> </Grid> </Page> |
▶ SampleCompactSizingPage.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 91 |
using Windows.UI.Xaml.Controls; namespace TestProject { /// <summary> /// 샘플 컴팩트 크기 페이지 /// </summary> public sealed partial class SampleCompactSizingPage : Page { //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region 이름 - FirstName /// <summary> /// 이름 /// </summary> public TextBox FirstName => this.firstNameTextBox; #endregion #region 성 - LastName /// <summary> /// 성 /// </summary> public TextBox LastName => this.lastNameTextBox; #endregion #region 패스워드 - Password /// <summary> /// 패스워드 /// </summary> public PasswordBox Password => this.passwordPasswordBox; #endregion #region 패스워드 확인 - ConfirmPassword /// <summary> /// 패스워드 확인 /// </summary> public PasswordBox ConfirmPassword => this.confirmPasswordPasswordBox; #endregion #region 선택 날짜 - ChosenDate /// <summary> /// 선택 날짜 /// </summary> public DatePicker ChosenDate => this.chosenDatePicker; #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - SampleCompactSizingPage() /// <summary> /// 생성자 /// </summary> public SampleCompactSizingPage() { InitializeComponent(); } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Public #region 상태 복사하기 - CopyState(page) /// <summary> /// 상태 복사하기 /// </summary> /// <param name="page">샘플 표준 크기 페이지</param> public void CopyState(SampleStandardSizingPage page) { FirstName.Text = page.FirstName.Text; LastName.Text = page.LastName.Text; Password.Password = page.Password.Password; ConfirmPassword.Password = page.ConfirmPassword.Password; ChosenDate.Date = page.ChosenDate.Date; } #endregion } } |
▶ SampleStandardSizingPage.xaml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
<Page x:Class="TestProject.SampleStandardSizingPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> <StackPanel Spacing="4"> <TextBlock Name="HeaderBlock" FontSize="18" Text="표준 크기" /> <TextBox Name="firstNameTextBox" Header="이름 :" /> <TextBox Name="lastNameTextBox" Header="성 :" /> <PasswordBox Name="passwordPasswordBox" Header="패스워드 :" /> <PasswordBox Name="confirmPasswordPasswordBox" Header="패스워드 확인 :" /> <DatePicker Name="chosenDatePicker" Header="날짜 선택" /> </StackPanel> </Grid> </Page> |
▶ SampleStandardSizingPage.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 91 |
using Windows.UI.Xaml.Controls; namespace TestProject { /// <summary> /// 샘플 표준 크기 페이지 /// </summary> public sealed partial class SampleStandardSizingPage : Page { //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region 이름 - FirstName /// <summary> /// 이름 /// </summary> public TextBox FirstName => this.firstNameTextBox; #endregion #region 성 - LastName /// <summary> /// 성 /// </summary> public TextBox LastName => this.lastNameTextBox; #endregion #region 패스워드 - Password /// <summary> /// 패스워드 /// </summary> public PasswordBox Password => this.passwordPasswordBox; #endregion #region 패스워드 확인 - ConfirmPassword /// <summary> /// 패스워드 확인 /// </summary> public PasswordBox ConfirmPassword => this.confirmPasswordPasswordBox; #endregion #region 선택 날짜 - ChosenDate /// <summary> /// 선택 날짜 /// </summary> public DatePicker ChosenDate => this.chosenDatePicker; #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - SampleStandardSizingPage() /// <summary> /// 생성자 /// </summary> public SampleStandardSizingPage() { InitializeComponent(); } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Public #region 상태 복사하기 - CopyState(page) /// <summary> /// 상태 복사하기 /// </summary> /// <param name="page">샘플 컴팩트 크기 페이지</param> public void CopyState(SampleCompactSizingPage page) { FirstName.Text = page.FirstName.Text; LastName.Text = page.LastName.Text; Password.Password = page.Password.Password; ConfirmPassword.Password = page.ConfirmPassword.Password; ChosenDate.Date = page.ChosenDate.Date; } #endregion } } |
▶ MainPage.xaml
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 |
<Page x:Class="TestProject.MainPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:muxc="using:Microsoft.UI.Xaml.Controls" Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" FontFamily="나눔고딕코딩" FontSize="16"> <Grid> <Grid HorizontalAlignment="Center" VerticalAlignment="Center"> <Grid.ColumnDefinitions> <ColumnDefinition Width="Auto" /> <ColumnDefinition Width="50" /> <ColumnDefinition Width="Auto" /> </Grid.ColumnDefinitions> <Frame Name="frame" Grid.Column="0" /> <muxc:RadioButtons Grid.Column="2" VerticalAlignment="Center" Header="플루언트 표준/컴팩트 크기"> <RadioButton GroupName="ControlSize" Tag="StandardSize" Content="표준" Checked="standardSizeRadioButton_Checked" IsChecked="True" /> <RadioButton GroupName="ControlSize" Tag="CompactSize" Content="컴팩트" Checked="compactSizeRadioButton_Checked" /> </muxc:RadioButtons> </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 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
using Windows.Foundation; using Windows.Graphics.Display; using Windows.UI.ViewManagement; using Windows.UI.Xaml; using Windows.UI.Xaml.Controls; using Windows.UI.Xaml.Media.Animation; namespace TestProject { /// <summary> /// 메인 페이지 /// </summary> public sealed partial class MainPage : Page { //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - MainPage() /// <summary> /// 생성자 /// </summary> public MainPage() { InitializeComponent(); #region 윈도우 크기를 설정한다. double width = 800d; double height = 600d; double dpi = (double)DisplayInformation.GetForCurrentView().LogicalDpi; ApplicationView.PreferredLaunchWindowingMode = ApplicationViewWindowingMode.PreferredLaunchViewSize; Size windowSize = new Size(width * 96d / dpi, height * 96d / dpi); ApplicationView.PreferredLaunchViewSize = windowSize; Window.Current.Activate(); ApplicationView.GetForCurrentView().TryResizeView(windowSize); #endregion #region 윈도우 제목을 설정한다. ApplicationView.GetForCurrentView().Title = "ResourceDictionary 엘리먼트 : Source 속성을 사용해 컨트롤 컴팩트 크기 사용하기"; #endregion Loaded += Page_Loaded; } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Private #region 페이지 로드시 처리하기 - Page_Loaded(sender, e) /// <summary> /// 페이지 로드시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void Page_Loaded(object sender, RoutedEventArgs e) { this.frame.Navigate(typeof(SampleStandardSizingPage), null, new SuppressNavigationTransitionInfo()); } #endregion #region 표준 크기 라디오 버튼 체크시 처리하기 - standardSizeRadioButton_Checked(sender, e) /// <summary> /// 표준 크기 라디오 버튼 클릭시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void standardSizeRadioButton_Checked(object sender, RoutedEventArgs e) { SampleCompactSizingPage previousPage = this.frame.Content as SampleCompactSizingPage; this.frame.Navigate(typeof(SampleStandardSizingPage), null, new SuppressNavigationTransitionInfo()); if(previousPage != null) { SampleStandardSizingPage currentPage = this.frame.Content as SampleStandardSizingPage; currentPage.CopyState(previousPage); } } #endregion #region 컴팩트 크기 라디오 버튼 체크시 처리하기 - compactSizeRadioButton_Checked(sender, e) /// <summary> /// 컴팩트 크기 라디오 버튼 체크시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void compactSizeRadioButton_Checked(object sender, RoutedEventArgs e) { SampleStandardSizingPage previousPage = this.frame.Content as SampleStandardSizingPage; this.frame.Navigate(typeof(SampleCompactSizingPage), null, new SuppressNavigationTransitionInfo()); if(previousPage != null) { SampleCompactSizingPage currentPage = this.frame.Content as SampleCompactSizingPage; currentPage.CopyState(previousPage); } } #endregion } } |