■ NavigationView 엘리먼트를 사용하는 방법을 보여준다.
▶ 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 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 |
<?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> <NavigationView Name="navigationView" Grid.Column="0" Header="{Binding ElementName=headerTextBox, Path=Text, Mode=TwoWay}" PaneTitle="{Binding ElementName=paneTextBox, Path=Text, Mode=TwoWay}" PaneDisplayMode="Left" ExpandedModeThresholdWidth="500" IsTabStop="False"> <NavigationView.MenuItems> <NavigationViewItem Name="navigationViewItem1" Content="Menu Item1" Tag="SamplePage1"> <NavigationViewItem.Icon> <SymbolIcon Symbol="Play" /> </NavigationViewItem.Icon> </NavigationViewItem> <NavigationViewItemHeader Content="Actions" /> <NavigationViewItem Name="navigationViewItem2" SelectsOnInvoked="True" Content="Menu Item2" Tag="SamplePage2"> <NavigationViewItem.Icon> <SymbolIcon Symbol="Save" /> </NavigationViewItem.Icon> </NavigationViewItem> <NavigationViewItem Name="navigationViewItem3" Content="Menu Item3" Tag="SamplePage3"> <NavigationViewItem.Icon> <SymbolIcon Symbol="Refresh" /> </NavigationViewItem.Icon> </NavigationViewItem> </NavigationView.MenuItems> <NavigationView.PaneCustomContent> <HyperlinkButton Name="paneHyperlinkButton" Margin="10 0" Content="More info" Visibility="Collapsed" /> </NavigationView.PaneCustomContent> <NavigationView.AutoSuggestBox> <AutoSuggestBox QueryIcon="Find" /> </NavigationView.AutoSuggestBox> <NavigationView.PaneFooter> <StackPanel Name="footerStackPanel" Orientation="Vertical" Visibility="Collapsed"> <NavigationViewItem Icon="Download" /> <NavigationViewItem Icon="Favorite" /> </StackPanel> </NavigationView.PaneFooter> <Frame Name="contentFrame" /> </NavigationView> <StackPanel Grid.Column="2" HorizontalAlignment="Center" VerticalAlignment="Center"> <CheckBox Name="settingsItemVisibleCheckBox" Content="Settings item visible" IsChecked="True" /> <CheckBox Name="backButtonVisibleCheckBox" Content="Back button visible" IsChecked="True" /> <CheckBox Name="backButtonEnabledCheckBox" Content="Back button enabled" IsChecked="False" /> <CheckBox Name="autoSuggestBoxVisibleCheckBox" Content="AutoSuggestBox visible" IsChecked="True" /> <TextBlock Text="Header :" Margin="0 10 0 0" /> <TextBox Name="headerTextBox" Text="Header" /> <CheckBox Name="alwaysShowHeaderCheckBox" Content="Always show header" IsChecked="True" /> <TextBlock Text="PaneTitle :" Margin="0 10 0 0" /> <TextBox Name="paneTextBox" Text="Pane Title" /> <CheckBox Name="paneCustomContentVisibleCheckBox" Content="PaneCustomContent visible" IsChecked="False" /> <CheckBox Name="paneFooterVisibleCheckBox" Content="PaneFooter visible" IsChecked="False" /> <TextBlock Margin="0 10 0 0" Text="PanePosition :" /> <RadioButton Name="leftPanePositionRadioButton" Content="Left" IsChecked="True" /> <RadioButton Name="topPanePositionRadioButton" Content="Top" /> <CheckBox Name="keyboardSelectionFollowsFocusCheckBox" Margin="0 10 0 0" Content="Keyboard SelectionFollowsFocus" IsChecked="False" /> <CheckBox Name="selectionSuppressedCheckBox" Content="Selection of Menu Item2 suppressed" IsChecked="False" /> </StackPanel> </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 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 |
using System; using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; namespace TestProject { /// <summary> /// 메인 페이지 /// </summary> public sealed partial class MainPage : Page { //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - MainPage() /// <summary> /// 생성자 /// </summary> public MainPage() { InitializeComponent(); this.navigationView.SelectionChanged += navigationView_SelectionChanged; this.settingsItemVisibleCheckBox.Click += settingsItemVisibleCheckBox_Click; this.backButtonVisibleCheckBox.Click += backButtonVisibleCheckBox_Click; this.backButtonEnabledCheckBox.Click += backButtonEnabledCheckBox_Click; this.autoSuggestBoxVisibleCheckBox.Click += autoSuggestBoxVisibleCheckBox_Click; this.alwaysShowHeaderCheckBox.Click += alwaysShowHeaderCheckBox_Click; this.paneCustomContentVisibleCheckBox.Click += paneCustomContentVisibleCheckBox_Click; this.paneFooterVisibleCheckBox.Click += paneFooterVisibleCheckBox_Click; this.leftPanePositionRadioButton.Checked += leftPanePositionRadioButton_Checked; this.topPanePositionRadioButton.Checked += topPanePositionRadioButton_Checked; this.keyboardSelectionFollowsFocusCheckBox.Click += keyboardSelectionFollowsFocusCheckBox_Click; this.selectionSuppressedCheckBox.Click += selectionSuppressedCheckBox_Click; } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Private #region 네비게이션 뷰 선택 변경시 처리하기 - navigationView_SelectionChanged(sender, e) /// <summary> /// 네비게이션 뷰 선택 변경시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void navigationView_SelectionChanged(NavigationView sender, NavigationViewSelectionChangedEventArgs e) { if(e.IsSettingsSelected) { this.contentFrame.Navigate(typeof(SampleSettingPage)); } else { NavigationViewItem selectedItem = e.SelectedItem as NavigationViewItem; if(selectedItem != null) { string selectedItemTag = selectedItem.Tag as string; sender.Header = "Sample Page " + selectedItemTag.Substring(selectedItemTag.Length - 1); string pageName = "TestProject." + selectedItemTag; Type pageType = Type.GetType(pageName); this.contentFrame.Navigate(pageType); } } } #endregion #region Settings item visible 체크 박스 클릭시 처리하기 - settingsItemVisibleCheckBox_Click(sender, e) /// <summary> /// Settings item visible 체크 박스 클릭시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void settingsItemVisibleCheckBox_Click(object sender, RoutedEventArgs e) { this.navigationView.IsSettingsVisible = (sender as CheckBox).IsChecked == true ? true : false; } #endregion #region Back button visible 체크 박스 클릭시 처리하기 - backButtonVisibleCheckBox_Click(sender, e) /// <summary> /// Back button visible 체크 박스 클릭시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void backButtonVisibleCheckBox_Click(object sender, RoutedEventArgs e) { if((sender as CheckBox).IsChecked == true) { this.navigationView.IsBackButtonVisible = NavigationViewBackButtonVisible.Visible; } else { this.navigationView.IsBackButtonVisible = NavigationViewBackButtonVisible.Collapsed; } } #endregion #region Back button enabled 체크 박스 클릭시 처리하기 - backButtonEnabledCheckBox_Click(sender, e) /// <summary> /// Back button enabled 체크 박스 클릭시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void backButtonEnabledCheckBox_Click(object sender, RoutedEventArgs e) { this.navigationView.IsBackEnabled = (sender as CheckBox).IsChecked == true ? true : false; } #endregion #region AutoSuggestBox visible 체크 박스 클릭시 처리하기 - autoSuggestBoxVisibleCheckBox_Click(sender, e) /// <summary> /// AutoSuggestBox visible 체크 박스 클릭시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void autoSuggestBoxVisibleCheckBox_Click(object sender, RoutedEventArgs e) { if((sender as CheckBox).IsChecked == true) { AutoSuggestBox autoSuggestBox = new AutoSuggestBox() { QueryIcon = new SymbolIcon(Symbol.Find) }; this.navigationView.AutoSuggestBox = autoSuggestBox; } else { this.navigationView.AutoSuggestBox = null; } } #endregion #region Always show header 체크 박스 클릭시 처리하기 - alwaysShowHeaderCheckBox_Click(sender, e) /// <summary> /// Always show header 체크 박스 클릭시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void alwaysShowHeaderCheckBox_Click(object sender, RoutedEventArgs e) { this.navigationView.AlwaysShowHeader = (sender as CheckBox).IsChecked == true ? true : false; } #endregion #region PaneCustomContent visible 체크 박스 클릭시 처리하기 - paneCustomContentVisibleCheckBox_Click(sender, e) /// <summary> /// PaneCustomContent visible 체크 박스 클릭시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void paneCustomContentVisibleCheckBox_Click(object sender, RoutedEventArgs e) { if((sender as CheckBox).IsChecked == true) { this.paneHyperlinkButton.Visibility = Visibility.Visible; } else { this.paneHyperlinkButton.Visibility = Visibility.Collapsed; } } #endregion #region PaneFooter visible 체크 박스 클릭시 처리하기 - paneFooterVisibleCheckBox_Click(sender, e) /// <summary> /// PaneFooter visible 체크 박스 클릭시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void paneFooterVisibleCheckBox_Click(object sender, RoutedEventArgs e) { if((sender as CheckBox).IsChecked == true) { this.footerStackPanel.Visibility = Visibility.Visible; } else { this.footerStackPanel.Visibility = Visibility.Collapsed; } } #endregion #region Left PanePosition 라디오 버튼 체크시 처리하기 - leftPanePositionRadioButton_Checked(sender, e) /// <summary> /// Left PanePosition 라디오 버튼 체크시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void leftPanePositionRadioButton_Checked(object sender, RoutedEventArgs e) { if((sender as RadioButton).IsChecked == true) { this.navigationView.PaneDisplayMode = NavigationViewPaneDisplayMode.Left; this.navigationView.IsPaneOpen = true; this.footerStackPanel.Orientation = Orientation.Vertical; } } #endregion #region Top PanePosition 라디오 버튼 체크시 처리하기 - topPanePositionRadioButton_Checked(sender, e) /// <summary> /// Top PanePosition 라디오 버튼 체크시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void topPanePositionRadioButton_Checked(object sender, RoutedEventArgs e) { if((sender as RadioButton).IsChecked == true) { this.navigationView.PaneDisplayMode = NavigationViewPaneDisplayMode.Top; this.navigationView.IsPaneOpen = false; this.footerStackPanel.Orientation = Orientation.Horizontal; } } #endregion #region Keyboard SelectionFollowsFocus 체크 박스 클릭시 처리하기 - keyboardSelectionFollowsFocusCheckBox_Click(sender, e) /// <summary> /// Keyboard SelectionFollowsFocus 체크 박스 클릭시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void keyboardSelectionFollowsFocusCheckBox_Click(object sender, RoutedEventArgs e) { if((sender as CheckBox).IsChecked == true) { this.navigationView.SelectionFollowsFocus = NavigationViewSelectionFollowsFocus.Enabled; } else { this.navigationView.SelectionFollowsFocus = NavigationViewSelectionFollowsFocus.Disabled; } } #endregion #region Selection of Menu Item2 suppressed 체크 박스 클릭시 처리하기 - selectionSuppressedCheckBox_Click(sender, e) /// <summary> /// Selection of Menu Item2 suppressed 체크 박스 클릭시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void selectionSuppressedCheckBox_Click(object sender, RoutedEventArgs e) { this.navigationViewItem2.SelectsOnInvoked = (sender as CheckBox).IsChecked == true ? false : true; } #endregion } } |