■ DoubleAnimation 클래스를 사용해 윈도우 하단에 마우스 위치시 하단 패널을 표시하는 애니메이션을 만드는 방법을 보여준다.
▶ 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 |
<Window x:Class="TestProject.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Height="600" Width="800" Title="TestProject" FontFamily="나눔고딕코딩" FontSize="16"> <Grid Name="contentGrid" Background="White"> <Grid.RowDefinitions> <RowDefinition Height="*" /> <RowDefinition Height="Auto" /> </Grid.RowDefinitions> <Border Name="bottomGrid" Grid.Row="1" Height="0" Background="#e0e0e0"> <TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" Text="Sliding Panel Content" /> </Border> </Grid> </Window> |
▶ 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 System; using System.Windows; using System.Windows.Input; using System.Windows.Media.Animation; namespace TestProject; /// <summary> /// 메인 윈도우 /// </summary> public partial class MainWindow : Window { //////////////////////////////////////////////////////////////////////////////////////////////////// Field ////////////////////////////////////////////////////////////////////////////////////////// Private #region Field /// <summary> /// 하단 그리드 표시 여부 /// </summary> private bool isBottomGridVisible = false; #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - MainWindow() /// <summary> /// 생성자 /// </summary> public MainWindow() { InitializeComponent(); this.contentGrid.MouseMove += contentGrid_MouseMove; this.bottomGrid.MouseLeave += bottomGrid_MouseLeave; } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Private //////////////////////////////////////////////////////////////////////////////// Event #region 컨텐트 그리드 마우스 이동시 처리하기 - contentGrid_MouseMove(sender, e) /// <summary> /// 컨텐트 그리드 마우스 이동시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void contentGrid_MouseMove(object sender, MouseEventArgs e) { Point mousePoint = e.GetPosition(this); if(mousePoint.Y > this.contentGrid.ActualHeight - 30) { if(!this.isBottomGridVisible) { ShowBottomGrid(); } } } #endregion #region 하단 그리드 마우스 이탈시 처리하기 - bottomGrid_MouseLeave(sender, e) /// <summary> /// 하단 그리드 마우스 이탈시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void bottomGrid_MouseLeave(object sender, MouseEventArgs e) { if(this.isBottomGridVisible) { HideBottomGrid(); } } #endregion //////////////////////////////////////////////////////////////////////////////// Function #region 하단 그리드 표시하기 - ShowBottomGrid() /// <summary> /// 하단 그리드 표시하기 /// </summary> private void ShowBottomGrid() { DoubleAnimation doubleAnimation = new DoubleAnimation(100, TimeSpan.FromSeconds(0.3)); this.bottomGrid.BeginAnimation(HeightProperty, doubleAnimation); this.isBottomGridVisible = true; } #endregion #region 하단 그리드 숨기기 - HideBottomGrid() /// <summary> /// 하단 그리드 숨기기 /// </summary> private void HideBottomGrid() { DoubleAnimation doubleAnimation = new DoubleAnimation(0, TimeSpan.FromSeconds(0.3)); this.bottomGrid.BeginAnimation(HeightProperty, doubleAnimation); this.isBottomGridVisible = false; } #endregion } |