■ FlowDocumentReader 클래스에서 하단 컨트롤을 숨기는 방법을 보여준다.
▶ VisualHelper.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 System; using System.Windows; using System.Windows.Media; namespace TestProject; /// <summary> /// 비주얼 헬퍼 /// </summary> public static class VisualHelper { //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Static //////////////////////////////////////////////////////////////////////////////// Public #region 타입으로 자손 찾기 - FindDescendantByType(source, descendantType, specificTypeOnly) /// <summary> /// 타입으로 자손 찾기 /// </summary> /// <param name="source">소스 객체</param> /// <param name="descendantType">자손 타입</param> /// <param name="specificTypeOnly">특정 타입만 찾기 여부</param> /// <returns>자손 객체</returns> public static Visual FindDescendantByType(Visual source, Type descendantType, bool specificTypeOnly) { if(source == null) { return null; } if(specificTypeOnly ? (source.GetType() == descendantType) : (source.GetType() == descendantType) || (source.GetType().IsSubclassOf(descendantType))) { return source; } Visual target = null; if(source is FrameworkElement) { (source as FrameworkElement).ApplyTemplate(); } for(int i = 0; i < VisualTreeHelper.GetChildrenCount(source); i++) { Visual visual = VisualTreeHelper.GetChild(source, i) as Visual; target = FindDescendantByType(visual, descendantType, specificTypeOnly); if(target != null) { break; } } return target; } #endregion #region 타입으로 자손 찾기 - FindDescendantByType(source, descendantType) /// <summary> /// 타입으로 자손 찾기 /// </summary> /// <param name="source">소스 객체</param> /// <param name="descendantType">자손 타입</param> /// <returns>자손 객체</returns> public static Visual FindDescendantByType(Visual source, Type descendantType) { return FindDescendantByType(source, descendantType, true); } #endregion #region 타입으로 자손 찾기 - FindDescendantByType<TDescendant>(source) /// <summary> /// 타입으로 자손 찾기 /// </summary> /// <typeparam name="TDescendant">자손 타입</typeparam> /// <param name="source">소스 객체</param> /// <returns>자손 객체</returns> public static TDescendant FindDescendantByType<TDescendant>(Visual source) where TDescendant : Visual { Visual target = VisualHelper.FindDescendantByType(source, typeof(TDescendant)); return (TDescendant)target; } #endregion } |
▶ FlowDocumentExtension.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 |
using System.Windows; using System.Windows.Controls; namespace TestProject; /// <summary> /// 플로우 문서 확장 /// </summary> public static class FlowDocumentExtension { //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Static //////////////////////////////////////////////////////////////////////////////// Public #region 컨트롤러 표시 여부 설정하기 - SetControllerVisibility(flowDocumentReader, visibility) /// <summary> /// 컨트롤러 표시 여부 설정하기 /// </summary> /// <param name="flowDocumentReader">플로우 문서 리더</param> /// <param name="visibility">표시 여부</param> public static void SetControllerVisibility(this FlowDocumentReader flowDocumentReader, Visibility visibility) { DockPanel childDockPanel = VisualHelper.FindDescendantByType<DockPanel>(flowDocumentReader); Grid grandChildGrid = VisualHelper.FindDescendantByType<Grid>(childDockPanel); Grid grandGrandChildGrid = VisualHelper.FindDescendantByType<Grid>(grandChildGrid); grandGrandChildGrid.Visibility = visibility; } #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 34 35 36 |
<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"> <Border Margin="10" BorderThickness="1" BorderBrush="DarkGray"> <FlowDocumentReader Name="flowDocumentReader" Padding="10"> <FlowDocument> <Paragraph> <Run>테스트 문자열 입니다.</Run> </Paragraph> <Paragraph> <Run>테스트 문자열 입니다.</Run> </Paragraph> <Paragraph> <Run>테스트 문자열 입니다.</Run> </Paragraph> <Paragraph> <Run>테스트 문자열 입니다.</Run> </Paragraph> <Paragraph> <Run>테스트 문자열 입니다.</Run> </Paragraph> </FlowDocument> </FlowDocumentReader> </Border> </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 |
using System.Windows; namespace TestProject; /// <summary> /// 메인 윈도우 /// </summary> public partial class MainWindow : Window { //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - MainWindow() /// <summary> /// 생성자 /// </summary> public MainWindow() { InitializeComponent(); this.flowDocumentReader.SetControllerVisibility(Visibility.Collapsed); } #endregion } |