C,C++
[C/C++/C#/UWP] UWP Customized SplitView 코드 - 2
덜지
2016. 10. 21. 18:11
Customized SplitView 를 ListBox를 이용하여 더욱 간편하게 구현할 수 있습니다.
전체코드
MainPage.xmal
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 | <Page x:Class="ListBox1.MainPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="using:ListBox1" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d"> <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> <SplitView x:Name="SplitView" OpenPaneLength="200" CompactPaneLength="50" DisplayMode="CompactOverlay" IsPaneOpen="False" PaneBackground="DarkGray"> <SplitView.Pane> <ListBox SelectionMode="Single" SelectionChanged="ListBox_SelectionChanged"> <ListBoxItem Name="Back" Background="Gray"> <StackPanel Orientation="Horizontal"> <TextBlock FontFamily="Segoe MDL2 Assets" FontSize="30" Text=""/> <TextBlock FontSize="24" Margin="10,0,0,0">Back</TextBlock> </StackPanel> </ListBoxItem> <ListBoxItem Name="Hamburger" > <StackPanel Orientation="Horizontal"> <TextBlock FontFamily="Segoe MDL2 Assets" FontSize="30" Text=""/> <TextBlock FontSize="24" Margin="10,0,0,0">Menu</TextBlock> </StackPanel> </ListBoxItem> <ListBoxItem Name="Home" > <StackPanel Orientation="Horizontal"> <TextBlock FontFamily="Segoe MDL2 Assets" FontSize="30" Text=""/> <TextBlock FontSize="24" Margin="10,0,0,0">Home</TextBlock> </StackPanel> </ListBoxItem> <ListBoxItem Name="Settings" > <StackPanel Orientation="Horizontal"> <TextBlock FontFamily="Segoe MDL2 Assets" FontSize="30" Text=""/> <TextBlock FontSize="24" Margin="10,0,0,0">Settings</TextBlock> </StackPanel> </ListBoxItem> </ListBox> </SplitView.Pane> <SplitView.Content> <Frame x:Name="MyFrame"> </Frame> </SplitView.Content> </SplitView> </Grid> </Page> | cs |
MainPage.xmal.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 | using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Runtime.InteropServices.WindowsRuntime; using Windows.Foundation; using Windows.Foundation.Collections; using Windows.UI.Xaml; using Windows.UI.Xaml.Controls; using Windows.UI.Xaml.Controls.Primitives; using Windows.UI.Xaml.Data; using Windows.UI.Xaml.Input; using Windows.UI.Xaml.Media; using Windows.UI.Xaml.Navigation; // 빈 페이지 항목 템플릿은 http://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409 에 문서화되어 있습니다. namespace ListBox1 { /// <summary> /// 자체적으로 사용하거나 프레임 내에서 탐색할 수 있는 빈 페이지입니다. /// </summary> public sealed partial class MainPage : Page { public MainPage() { this.InitializeComponent(); MyFrame.Navigate(typeof(Page1)); } private void ListBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (Back.IsSelected) { if(MyFrame.CanGoBack) { MyFrame.GoBack(); } } else if (Hamburger.IsSelected) { if(!this.SplitView.IsPaneOpen) { this.SplitView.IsPaneOpen = true; } else { this.SplitView.IsPaneOpen = false; } } else if (Home.IsSelected) { MyFrame.Navigate(typeof(Page1)); } else if (Settings.IsSelected) { MyFrame.Navigate(typeof(page2)); } else { // do nothing } } } } | cs |