■ 컨트롤의 컴팩트 크기를 설정하는 방법을 보여준다.
▶ 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 24 |
<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 Name="CompactPanel" Spacing="15"> <TextBlock FontSize="18" Text="Standard Size" /> <TextBox Name="firstNameTextBox" Header="First Name : " /> <TextBox Name="lastNameTextBox" Header="Last Name : " /> <PasswordBox Name="passwordBox" Header="Password : " /> <PasswordBox Name="confirmPasswordBox" Header="Confirm Password : " /> <DatePicker Name="chosenDatePicker" Header="Pick a date" /> </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 Microsoft.UI.Xaml.Controls; namespace TestProject { /// <summary> /// 샘플 표준 크기 페이지 /// </summary> public sealed partial class SampleStandardSizingPage : Page { //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region 이름 텍스트 박스 - FirstNameTextBox /// <summary> /// 이름 텍스트 박스 /// </summary> public TextBox FirstNameTextBox => this.firstNameTextBox; #endregion #region 성 텍스트 박스 - LastNameTextBox /// <summary> /// 성 텍스트 박스 /// </summary> public TextBox LastNameTextBox => this.lastNameTextBox; #endregion #region 패스워드 박스 - PasswordBox /// <summary> /// 패스워드 박스 /// </summary> public PasswordBox PasswordBox => this.passwordBox; #endregion #region 확인 패스워드 박스 - ConfirmPasswordBox /// <summary> /// 확인 패스워드 박스 /// </summary> public PasswordBox ConfirmPasswordBox => this.confirmPasswordBox; #endregion #region 선택 날짜 선택기 - ChosenDatePicker /// <summary> /// 선택 날짜 선택기 /// </summary> public DatePicker ChosenDatePicker => 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) { FirstNameTextBox.Text = page.FirstNameTextBox.Text; LastNameTextBox.Text = page.LastNameTextBox.Text; PasswordBox.Password = page.PasswordBox.Password; ConfirmPasswordBox.Password = page.ConfirmPasswordBox.Password; ChosenDatePicker.Date = page.ChosenDatePicker.Date; } #endregion } } |
▶ 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 27 28 29 30 |
<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="10"> <StackPanel.Resources> <Thickness x:Key="TextBoxTopHeaderMargin">0 2 0 2</Thickness> <Thickness x:Key="PasswordBoxTopHeaderMargin">0 2 0 2</Thickness> </StackPanel.Resources> <TextBlock FontSize="18" Text="Compact Size" /> <TextBox Name="firstNameTextBox" Header="First Name : " /> <TextBox Name="lastNameTextBox" Header="Last Name : " /> <PasswordBox Name="passwordBox" Header="Password : " /> <PasswordBox Name="confirmPasswordBox" Header="Confirm Password : " /> <DatePicker Name="chosenDatePicker" Header="Pick a date" /> </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 Microsoft.UI.Xaml.Controls; namespace TestProject { /// <summary> /// 샘플 컴팩트 크기 페이지 /// </summary> public sealed partial class SampleCompactSizingPage : Page { //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region 이름 텍스트 박스 - FirstNameTextBox /// <summary> /// 이름 텍스트 박스 /// </summary> public TextBox FirstNameTextBox => this.firstNameTextBox; #endregion #region 성 텍스트 박스 - LastNameTextBox /// <summary> /// 성 텍스트 박스 /// </summary> public TextBox LastNameTextBox => this.lastNameTextBox; #endregion #region 패스워드 박스 - PasswordBox /// <summary> /// 패스워드 박스 /// </summary> public PasswordBox PasswordBox => this.passwordBox; #endregion #region 확인 패스워드 박스 - ConfirmPasswordBox /// <summary> /// 확인 패스워드 박스 /// </summary> public PasswordBox ConfirmPasswordBox => this.confirmPasswordBox; #endregion #region 선택 날짜 선택기 - ChosenDatePicker /// <summary> /// 선택 날짜 선택기 /// </summary> public DatePicker ChosenDatePicker => 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) { FirstNameTextBox.Text = page.FirstNameTextBox.Text; LastNameTextBox.Text = page.LastNameTextBox.Text; PasswordBox.Password = page.PasswordBox.Password; ConfirmPasswordBox.Password = page.ConfirmPasswordBox.Password; ChosenDatePicker.Date = page.ChosenDatePicker.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 |
<?xml version="1.0" encoding="utf-8"?> <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 Margin="10"> <Grid.ColumnDefinitions> <ColumnDefinition Width="*" /> <ColumnDefinition Width="10" /> <ColumnDefinition Width="Auto" /> </Grid.ColumnDefinitions> <Frame Name="contentFrame" Grid.Column="0" /> <RadioButtons Grid.Column="2" HorizontalAlignment="Center" VerticalAlignment="Center" Header="Fluent Standard and Compact Sizing"> <RadioButton Name="standardRadioButton" GroupName="ControlSize" Tag="StandardSize" Content="Standard" /> <RadioButton Name="compactRadioButton" GroupName="ControlSize" Tag="CompactSize" Content="Compact" /> </RadioButtons> </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 |
using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; using Microsoft.UI.Xaml.Media.Animation; namespace TestProject { /// <summary> /// 메인 페이지 /// </summary> public sealed partial class MainPage : Page { //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - MainPage() /// <summary> /// 생성자 /// </summary> public MainPage() { InitializeComponent(); Loaded += Page_Loaded; this.standardRadioButton.Checked += standardRadioButton_Checked; this.compactRadioButton.Checked += compactRadioButton_Checked; this.standardRadioButton.IsChecked = true; } #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.contentFrame.Navigate(typeof(SampleStandardSizingPage), null, new SuppressNavigationTransitionInfo()); } #endregion #region Standard 라디오 버튼 체크시 처리하기 - standardRadioButton_Checked(sender, e) /// <summary> /// Standard 라디오 버튼 체크시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void standardRadioButton_Checked(object sender, RoutedEventArgs e) { SampleCompactSizingPage page1 = this.contentFrame.Content as SampleCompactSizingPage; this.contentFrame.Navigate(typeof(SampleStandardSizingPage), null, new SuppressNavigationTransitionInfo()); if(page1 != null) { SampleStandardSizingPage page2 = this.contentFrame.Content as SampleStandardSizingPage; page2.CopyState(page1); } } #endregion #region Compact 라디오 버튼 체크시 처리하기 - compactRadioButton_Checked(sender, e) /// <summary> /// Compact 라디오 버튼 체크시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void compactRadioButton_Checked(object sender, RoutedEventArgs e) { SampleStandardSizingPage page1 = this.contentFrame.Content as SampleStandardSizingPage; this.contentFrame.Navigate(typeof(SampleCompactSizingPage), null, new SuppressNavigationTransitionInfo()); if(page1 != null) { SampleCompactSizingPage page2 = this.contentFrame.Content as SampleCompactSizingPage; page2.CopyState(page1); } } #endregion } } |