■ ConnectedAnimation 클래스에서 연결 애니메이션 구성을 사용하는 방법을 보여준다.
▶ SimplePage1.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 |
<Page x:Class="TestProject.SamplePage1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" FontFamily="나눔고딕코딩" FontSize="16"> <ScrollViewer> <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> <Grid.Resources> <x:Double x:Key="TileHeightKey">150</x:Double> </Grid.Resources> <Grid.ColumnDefinitions> <ColumnDefinition Width="Auto" /> <ColumnDefinition Width="*" /> <ColumnDefinition Width="*" /> </Grid.ColumnDefinitions> <Grid.RowDefinitions> <RowDefinition Height="Auto" /> <RowDefinition Height="Auto" /> <RowDefinition Height="Auto" /> <RowDefinition Height="*" /> </Grid.RowDefinitions> <Grid Grid.Row="1" Grid.Column="1" Margin="5" MinHeight="{StaticResource TileHeightKey}" Background="DarkGray" /> <Grid Grid.Row="1" Grid.Column="2" Margin="5" MinHeight="{StaticResource TileHeightKey}" Background="LightGray" /> <Grid Grid.Row="2" Grid.Column="1" Margin="5" MinHeight="{StaticResource TileHeightKey}" Background="LightGray" /> <Grid Grid.Row="2" Grid.Column="2" Margin="5" MinHeight="{StaticResource TileHeightKey}" Background="DarkGray" /> <Grid Name="sourceGrid" Grid.Row="1" Grid.RowSpan="2" Grid.Column="0" Margin="5" MinWidth="250" MinHeight="{StaticResource TileHeightKey}" Background="{ThemeResource SystemAccentColor}" /> <Grid Grid.Row="3" Grid.ColumnSpan="3" Margin="5 10"> <TextBlock Style="{ThemeResource BodyTextBlockStyle}" TextWrapping="WrapWholeWords" Text="Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum." /> </Grid> </Grid> </ScrollViewer> </Page> |
▶ SimplePage1.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 |
using Windows.Foundation.Metadata; using Microsoft.UI.Xaml.Controls; using Microsoft.UI.Xaml.Media.Animation; using Microsoft.UI.Xaml.Navigation; namespace TestProject { /// <summary> /// 샘플 페이지 1 /// </summary> public sealed partial class SamplePage1 : Page { //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - SamplePage1() /// <summary> /// 생성자 /// </summary> public SamplePage1() { InitializeComponent(); } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Public #region 연결 애니메이션 준비하기 - PrepareConnectedAnimation(configuration) /// <summary> /// 연결 애니메이션 준비하기 /// </summary> /// <param name="configuration">연결 애니메이션 구성</param> public void PrepareConnectedAnimation(ConnectedAnimationConfiguration configuration) { ConnectedAnimation animation = ConnectedAnimationService.GetForCurrentView().PrepareToAnimate("ForwardConnectedAnimation", this.sourceGrid); if(configuration != null && ApiInformation.IsApiContractPresent("Windows.Foundation.UniversalApiContract", 7)) { animation.Configuration = configuration; } } #endregion ////////////////////////////////////////////////////////////////////////////////////////// Protected #region 탐색되는 경우 처리하기 - OnNavigatedTo(e) /// <summary> /// 탐색되는 경우 처리하기 /// </summary> /// <param name="e">이벤트 인자</param> protected override void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); ConnectedAnimation animation = ConnectedAnimationService.GetForCurrentView().GetAnimation("BackwardConnectedAnimation"); if(animation != null) { animation.TryStart(this.sourceGrid); } } #endregion } } |
▶ SimplePage2.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 |
<Page x:Class="TestProject.SamplePage2" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <ScrollViewer> <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> <Grid.Resources> <x:Double x:Key="TileHeightKey">150</x:Double> </Grid.Resources> <Grid.ColumnDefinitions> <ColumnDefinition Width="Auto" /> <ColumnDefinition Width="*" /> </Grid.ColumnDefinitions> <Grid.RowDefinitions> <RowDefinition Height="Auto" /> <RowDefinition Height="Auto" /> </Grid.RowDefinitions> <Grid Name="targetGrid" Grid.Row="1" Grid.Column="0" VerticalAlignment="Top" Margin="10" Width="150" Height="200" MinHeight="{StaticResource TileHeightKey}" Background="{ThemeResource SystemAccentColor}" /> <StackPanel Name="contentStackPanel" Grid.Row="1" Grid.Column="1" Margin="10" MinHeight="200"> <TextBlock Style="{ThemeResource TitleTextBlockStyle}" Margin="0 0 0 10" TextWrapping="WrapWholeWords" Text="Lorem ipsum dolor sit amet, consectetur adipiscing elit" /> <TextBlock TextWrapping="WrapWholeWords" Text="Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum." /> </StackPanel> </Grid> </ScrollViewer> </Page> |
▶ SimplePage2.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 |
using Windows.Foundation.Metadata; using Microsoft.UI.Xaml.Controls; using Microsoft.UI.Xaml.Media.Animation; using Microsoft.UI.Xaml.Navigation; namespace TestProject { /// <summary> /// 생성자 /// </summary> public sealed partial class SamplePage2 : Page { //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - SamplePage2() /// <summary> /// 생성자 /// </summary> public SamplePage2() { InitializeComponent(); } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Public #region 연결 애니메이션 준비하기 - PrepareConnectedAnimation(configuration) /// <summary> /// 연결 애니메이션 준비하기 /// </summary> /// <param name="configuration">연결 애니메이션 구성</param> public void PrepareConnectedAnimation(ConnectedAnimationConfiguration configuration) { ConnectedAnimation animation = ConnectedAnimationService.GetForCurrentView().PrepareToAnimate("BackwardConnectedAnimation", this.targetGrid); if(configuration != null && ApiInformation.IsApiContractPresent("Windows.Foundation.UniversalApiContract", 7)) { animation.Configuration = configuration; } } #endregion ////////////////////////////////////////////////////////////////////////////////////////// Protected #region 탐색되는 경우 처리하기 - OnNavigatedTo(e) /// <summary> /// 탐색되는 경우 처리하기 /// </summary> /// <param name="e">이벤트 인자</param> protected override void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); ConnectedAnimation animation = ConnectedAnimationService.GetForCurrentView().GetAnimation("ForwardConnectedAnimation"); if(animation != null) { this.contentStackPanel.Transitions = new TransitionCollection { new EntranceThemeTransition() }; animation.TryStart(this.targetGrid); } } #endregion } } |
▶ MainWindow.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 |
<?xml version="1.0" encoding="utf-8"?> <Window x:Class="TestProject.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="TestProject"> <Grid Margin="10"> <Grid.ColumnDefinitions> <ColumnDefinition Width="*" /> <ColumnDefinition Width="10" /> <ColumnDefinition Width="Auto" /> </Grid.ColumnDefinitions> <Frame Name="frame" Grid.Column="0" /> <StackPanel Grid.Column="2"> <Button Name="navigateButton" Padding="10" Content="Navigate" /> <TextBlock Style="{ThemeResource BaseTextBlockStyle}" Margin="0 10 0 0" Text="Configurations" /> <RadioButtons Name="configurationRadioButtons" Margin="0 10 0 0" SelectedIndex="0"> <RadioButton Content="Default" /> <RadioButton Content="Gravity" /> <RadioButton Content="Direct" /> <RadioButton Content="Basic" /> </RadioButtons> </StackPanel> </Grid> </Window> |
▶ MainWindow.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 |
using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; using Microsoft.UI.Xaml.Media.Animation; namespace TestProject { /// <summary> /// 메인 윈도우 /// </summary> public sealed partial class MainWindow : Window { //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - MainWindow() /// <summary> /// 생성자 /// </summary> public MainWindow() { InitializeComponent(); this.frame.Navigate(typeof(SamplePage1)); this.navigateButton.Click += navigateButton_Click; } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Private //////////////////////////////////////////////////////////////////////////////// Event #region Navigate 버튼 클릭시 처리하기 - navigateButton_Click(sender, e) /// <summary> /// Navigate 버튼 클릭시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void navigateButton_Click(object sender, RoutedEventArgs e) { object content = this.frame.Content; if(content as SamplePage1 != null) { (content as SamplePage1).PrepareConnectedAnimation(GetConnectedAnimationConfiguration()); this.frame.Navigate(typeof(SamplePage2), null, new SuppressNavigationTransitionInfo()); } else if(content as SamplePage2 != null) { (content as SamplePage2).PrepareConnectedAnimation(GetConnectedAnimationConfiguration()); this.frame.Navigate(typeof(SamplePage1), null, new SuppressNavigationTransitionInfo()); } } #endregion //////////////////////////////////////////////////////////////////////////////// Function #region 연결 애니메이션 구성 구하기 - GetConnectedAnimationConfiguration() /// <summary> /// 연결 애니메이션 구성 구하기 /// </summary> /// <returns>연결 애니메이션 구성</returns> private ConnectedAnimationConfiguration GetConnectedAnimationConfiguration() { if(this.configurationRadioButtons == null) { return null; } string selectedName = (configurationRadioButtons.SelectedItem as RadioButton).Content.ToString(); switch(selectedName) { case "Gravity" : return new GravityConnectedAnimationConfiguration(); case "Direct" : return new DirectConnectedAnimationConfiguration(); case "Basic" : return new BasicConnectedAnimationConfiguration(); default : return null; } } #endregion } } |