728x90
반응형
728x170
■ ControlTemplate 엘리먼트를 사용해 DocumentViewer 엘리먼트를 정의하는 방법을 보여준다.
▶ MainWindow.xaml
<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">
<Window.Resources>
<Color x:Key="ControlLightColor">White</Color>
<Color x:Key="ControlMediumColor">#ff7381f9</Color>
<Style x:Key="{x:Type DocumentViewer}" TargetType="{x:Type DocumentViewer}">
<Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey }}" />
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.WindowTextBrushKey}}" />
<Setter Property="FocusVisualStyle" Value="{x:Null}" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type DocumentViewer}">
<Border
BorderThickness="{TemplateBinding BorderThickness}"
BorderBrush="{TemplateBinding BorderBrush}"
Focusable="False">
<Grid KeyboardNavigation.TabNavigation="Local">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions> <Grid.Background>
<SolidColorBrush Color="{DynamicResource ControlLightColor}" />
</Grid.Background>
<ToolBar
ToolBarTray.IsLocked="True"
KeyboardNavigation.TabNavigation="Continue">
<Button
CommandTarget="{Binding RelativeSource={RelativeSource TemplatedParent}}"
Command="ApplicationCommands.Print"
Content="Print" />
<Button
Command="ApplicationCommands.Copy"
CommandTarget="{Binding RelativeSource={RelativeSource TemplatedParent}}"
Content="Copy" />
<Separator />
<Button
Command="NavigationCommands.IncreaseZoom"
CommandTarget="{Binding RelativeSource={RelativeSource TemplatedParent}}"
Content="Zoom In" />
<Button
Command="NavigationCommands.DecreaseZoom"
CommandTarget="{Binding RelativeSource={RelativeSource TemplatedParent}}"
Content="Zoom Out" />
<Separator />
<Button
Command="NavigationCommands.Zoom"
CommandTarget="{Binding RelativeSource={RelativeSource TemplatedParent}}"
CommandParameter="100.0"
Content="Actual Size" />
<Button
Command="DocumentViewer.FitToWidthCommand"
CommandTarget="{Binding RelativeSource={RelativeSource TemplatedParent}}"
Content="Fit to Width" />
<Button
Command="DocumentViewer.FitToMaxPagesAcrossCommand"
CommandTarget="{Binding RelativeSource={RelativeSource TemplatedParent}}"
CommandParameter="1"
Content="Whole Page" />
<Button
Command="DocumentViewer.FitToMaxPagesAcrossCommand"
CommandTarget="{Binding RelativeSource={RelativeSource TemplatedParent}}"
CommandParameter="2"
Content="Two Pages" />
</ToolBar>
<ScrollViewer Name="PART_ContentHost" Grid.Row="1"
CanContentScroll="true"
HorizontalScrollBarVisibility="Auto"
IsTabStop="true">
<ScrollViewer.Background>
<LinearGradientBrush
StartPoint="0.5 0"
EndPoint="0.5 1">
<GradientStop Offset="0" Color="{DynamicResource ControlLightColor }" />
<GradientStop Offset="1" Color="{DynamicResource ControlMediumColor}" />
</LinearGradientBrush>
</ScrollViewer.Background>
</ScrollViewer>
<ContentControl Name="PART_FindToolBarHost" Grid.Row="2" />
</Grid>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
<DocumentViewer Name="documentViewer"
Margin="10" />
</Window>
▶ MainWindow.xaml.cs
using System.IO;
using System.Windows;
using System.Windows.Documents;
using System.Windows.Xps.Packaging;
namespace TestProject
{
/// <summary>
/// 메인 윈도우
/// </summary>
public partial class MainWindow : Window
{
//////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
////////////////////////////////////////////////////////////////////////////////////////// Public
#region 생성자 - MainWindow()
/// <summary>
/// 생성자
/// </summary>
public MainWindow()
{
InitializeComponent();
XpsDocument xpsDocument = new XpsDocument("sample.xps", FileAccess.Read);
FixedDocumentSequence sequence = xpsDocument.GetFixedDocumentSequence();
FixedDocument fixedDocument = sequence.References[0].GetDocument(false);
this.documentViewer.Document = fixedDocument.DocumentPaginator.Source;
}
#endregion
}
}
728x90
반응형
그리드형(광고전용)
'C# > WPF' 카테고리의 다른 글
[C#/WPF] ControlTemplate 엘리먼트 : ListBox 엘리먼트 정의하기 (0) | 2023.01.27 |
---|---|
[C#/WPF] ControlTemplate 엘리먼트 : Label 엘리먼트 정의하기 (0) | 2023.01.27 |
[C#/WPF] ControlTemplate 엘리먼트 : GroupBox 엘리먼트 정의하기 (0) | 2023.01.27 |
[C#/WPF] ControlTemplate 엘리먼트 : Frame 엘리먼트 정의하기 (0) | 2023.01.27 |
[C#/WPF] ControlTemplate 엘리먼트 : Expander 엘리먼트 정의하기 (0) | 2023.01.25 |
[C#/WPF] ControlTemplate 엘리먼트 : DatePicker 엘리먼트 정의하기 (0) | 2023.01.25 |
[C#/WPF] ControlTemplate 엘리먼트 : DataGrid 엘리먼트 정의하기 (0) | 2023.01.24 |
[C#/WPF] ControlTemplate 엘리먼트 : ContextMenu 엘리먼트 정의하기 (0) | 2023.01.23 |
[C#/WPF] ControlTemplate 엘리먼트 : ComboBox 엘리먼트 정의하기 (0) | 2023.01.23 |
[C#/WPF] ControlTemplate 엘리먼트 : CheckBox 엘리먼트 정의하기 (0) | 2023.01.23 |
댓글을 달아 주세요