■ ScrollViewer 클래스의 컨텐츠 스크롤 메소드를 사용하는 방법을 보여준다.
▶ 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 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 |
<Window x:Class="TestProject.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Width="800" Height="600" Title="TestProject" FontFamily="나눔고딕코딩" FontSize="16"> <DockPanel Margin="10"> <StackPanel DockPanel.Dock="Left" Margin="30 30 0 0"> <Button Name="lineUpButton" Margin="0 10 0 0" Width="150" Height="30"> Line Up </Button> <Button Name="lineDownButton" Margin="0 10 0 0" Width="150" Height="30"> Line Down </Button> <Button Name="lineLeftButton" Margin="0 10 0 0" Width="150" Height="30"> Line Left </Button> <Button Name="lineRightButton" Margin="0 10 0 0" Width="150" Height="30"> Line Right </Button> <Button Name="pageUpButton" Margin="0 10 0 0" Width="150" Height="30"> Page Up </Button> <Button Name="pageDownButton" Margin="0 10 0 0" Width="150" Height="30"> Page Down </Button> <Button Name="pageLeftButton" Margin="0 10 0 0" Width="150" Height="30"> Page Left </Button> <Button Name="pageRightButton" Margin="0 10 0 0" Width="150" Height="30"> Page Right </Button> </StackPanel> <Border VerticalAlignment="Center" Width="500" Height="500" BorderThickness="2" BorderBrush="Black" Background="White"> <ScrollViewer Name="scrollViewer" VerticalScrollBarVisibility="Visible" HorizontalScrollBarVisibility="Auto"> <TextBlock Width="800" Height="1000" TextWrapping="Wrap" /> </ScrollViewer> </Border> </DockPanel> </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 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 |
using System.Windows; namespace TestProject { /// <summary> /// 메인 윈도우 /// </summary> public partial class MainWindow : Window { //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - MainWindow() /// <summary> /// 생성자 /// </summary> public MainWindow() { InitializeComponent(); this.lineUpButton.Click += lineUpButton_Click; this.lineDownButton.Click += lineDownButton_Click; this.lineLeftButton.Click += lineLeftButton_Click; this.lineRightButton.Click += lineRightButton_Click; this.pageUpButton.Click += pageUpButton_Click; this.pageDownButton.Click += pageDownButton_Click; this.pageLeftButton.Click += pageLeftButton_Click; this.pageRightButton.Click += pageRightButton_Click; } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Private #region Line Up 버튼 클릭시 처리하기 - lineUpButton_Click(sender, e) /// <summary> /// Line Up 버튼 클릭시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void lineUpButton_Click(object sender, RoutedEventArgs e) { this.scrollViewer.LineUp(); } #endregion #region Line Down 버튼 클릭시 처리하기 - lineDownButton_Click(sender, e) /// <summary> /// Line Down 버튼 클릭시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void lineDownButton_Click(object sender, RoutedEventArgs e) { this.scrollViewer.LineDown(); } #endregion #region Line Left 버튼 클릭시 처리하기 - lineLeftButton_Click(sender, e) /// <summary> /// Line Left 버튼 클릭시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void lineLeftButton_Click(object sender, RoutedEventArgs e) { this.scrollViewer.LineLeft(); } #endregion #region Line Right 버튼 클릭시 처리하기 - lineRightButton_Click(sender, e) /// <summary> /// Line Right 버튼 클릭시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void lineRightButton_Click(object sender, RoutedEventArgs e) { this.scrollViewer.LineRight(); } #endregion #region Page Up 버튼 클릭시 처리하기 - pageUpButton_Click(sender, e) /// <summary> /// Page Up 버튼 클릭시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void pageUpButton_Click(object sender, RoutedEventArgs e) { this.scrollViewer.PageUp(); } #endregion #region Page Down 버튼 클릭시 처리하기 - pageDownButton_Click(sender, e) /// <summary> /// Page Down 버튼 클릭시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void pageDownButton_Click(object sender, RoutedEventArgs e) { this.scrollViewer.PageDown(); } #endregion #region Page Left 버튼 클릭시 처리하기 - pageLeftButton_Click(sender, e) /// <summary> /// Page Left 버튼 클릭시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void pageLeftButton_Click(object sender, RoutedEventArgs e) { this.scrollViewer.PageLeft(); } #endregion #region Page Right 버튼 클릭시 처리하기 - pageRightButton_Click(sender, e) /// <summary> /// Page Right 버튼 클릭시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void pageRightButton_Click(object sender, RoutedEventArgs e) { this.scrollViewer.PageRight(); } #endregion } } |