■ FlowDocumentScrollViewer 클래스에서 문서 끝까지 스크롤하는 방법을 보여준다.
▶ 예제 코드 (C#)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
using System.Windows.Controls; // ... FlowDocumentScrollViewer flowDocumentScrollViewer; // ... FlowDocumentScrollViewerHelper helper = new FlowDocumentScrollViewerHelper(flowDocumentScrollViewer); // ... helper.ScrollToEnd(); |
▶ FlowDocumentScrollViewerHelper.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 |
using System.Windows; using System.Windows.Controls; using System.Windows.Media; /// <summary> /// 플로우 문서 스크롤 뷰어 헬퍼 /// </summary> public class FlowDocumentScrollViewerHelper { //////////////////////////////////////////////////////////////////////////////////////////////////// Field ////////////////////////////////////////////////////////////////////////////////////////// Private #region Field /// <summary> /// 플로우 문서 스크롤 뷰어 /// </summary> private FlowDocumentScrollViewer flowDocumentScrollViewer; /// <summary> /// 스크롤 뷰어 /// </summary> private ScrollViewer scrollViewer; #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - FlowDocumentScrollViewerHelper(flowDocumentScrollViewer) /// <summary> /// 생성자 /// </summary> /// <param name="flowDocumentScrollViewer">플로우 문서 스크롤 뷰어</param> public FlowDocumentScrollViewerHelper(FlowDocumentScrollViewer flowDocumentScrollViewer) { this.flowDocumentScrollViewer = flowDocumentScrollViewer; this.scrollViewer = GetScrollViewer(this.flowDocumentScrollViewer); } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Public #region 끝까지 스크롤하기 - ScrollToEnd() /// <summary> /// 끝까지 스크롤하기 /// </summary> public void ScrollToEnd() { if(this.scrollViewer != null) { scrollViewer.ScrollToEnd(); } } #endregion ////////////////////////////////////////////////////////////////////////////////////////// Private #region 스크롤 뷰어 찾기 - GetScrollViewer(dependencyObject) /// <summary> /// 스크롤 뷰어 찾기 /// </summary> /// <param name="dependencyObject">의존 객체</param> /// <returns>스크롤 뷰어</returns> private ScrollViewer GetScrollViewer(DependencyObject dependencyObject) { if(dependencyObject is ScrollViewer scrollViewer) { return scrollViewer; } for(int i = 0; i < VisualTreeHelper.GetChildrenCount(dependencyObject); i++) { DependencyObject childDependencyObject = VisualTreeHelper.GetChild(dependencyObject, i); ScrollViewer targetScrollViewer = GetScrollViewer(childDependencyObject); if(targetScrollViewer != null) { return targetScrollViewer; } } return null; } #endregion } |