Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The "FlowDocumentPageViewer" control is the basis for the "preview" control used in one of our projects. Here is the XAML of the "DocumentPreviewer" control (apologies for the length -- XAML is not succinct):</p> <pre><code>&lt;Control xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:sys="clr-namespace:System;assembly=mscorlib" xmlns:l="clr-namespace:Tyler.ComPort.UI" mc:Ignorable="d" x:Class="Tyler.ComPort.UI.DocumentPreviewer" x:Name="UserControl" Background="Gray" d:DesignWidth="640" d:DesignHeight="480"&gt; &lt;Control.Resources&gt; &lt;ObjectDataProvider x:Key="ViewStyles" MethodName="GetValues" ObjectType="{x:Type sys:Enum}" &gt; &lt;ObjectDataProvider.MethodParameters&gt; &lt;x:Type TypeName="l:ViewType" /&gt; &lt;/ObjectDataProvider.MethodParameters&gt; &lt;/ObjectDataProvider&gt; &lt;l:EnumMatchVisibilityConverter x:Key="EnumVisibilityConverter" /&gt; &lt;/Control.Resources&gt; &lt;Control.Template&gt; &lt;ControlTemplate&gt; &lt;ControlTemplate.Triggers&gt; &lt;Trigger Property="l:DocumentPreviewer.ViewType"&gt; &lt;Trigger.Value&gt; &lt;l:ViewType&gt;Actual&lt;/l:ViewType&gt; &lt;/Trigger.Value&gt; &lt;Trigger.Setters&gt; &lt;Setter TargetName="ScrollViewer" Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto" /&gt; &lt;Setter TargetName="ScrollViewer" Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto" /&gt; &lt;Setter TargetName="Viewbox" Property="Viewbox.Stretch" Value="None" /&gt; &lt;/Trigger.Setters&gt; &lt;/Trigger&gt; &lt;Trigger Property="l:DocumentPreviewer.ViewType"&gt; &lt;Trigger.Value&gt; &lt;l:ViewType&gt;Fit&lt;/l:ViewType&gt; &lt;/Trigger.Value&gt; &lt;Trigger.Setters&gt; &lt;Setter TargetName="ScrollViewer" Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Disabled" /&gt; &lt;Setter TargetName="ScrollViewer" Property="ScrollViewer.VerticalScrollBarVisibility" Value="Disabled" /&gt; &lt;Setter TargetName="Viewbox" Property="Viewbox.Stretch" Value="Uniform" /&gt; &lt;/Trigger.Setters&gt; &lt;/Trigger&gt; &lt;Trigger Property="l:DocumentPreviewer.ViewType"&gt; &lt;Trigger.Value&gt; &lt;l:ViewType&gt;Wide&lt;/l:ViewType&gt; &lt;/Trigger.Value&gt; &lt;Trigger.Setters&gt; &lt;Setter TargetName="ScrollViewer" Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Disabled" /&gt; &lt;Setter TargetName="ScrollViewer" Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto" /&gt; &lt;Setter TargetName="Viewbox" Property="Viewbox.Stretch" Value="UniformToFill" /&gt; &lt;/Trigger.Setters&gt; &lt;/Trigger&gt; &lt;/ControlTemplate.Triggers&gt; &lt;DockPanel&gt; &lt;ToolBar DockPanel.Dock="Top"&gt; &lt;Button Command="{x:Static ApplicationCommands.Print}" CommandTarget="{Binding ElementName=PageViewer}" Content="Print..." /&gt; &lt;Separator /&gt; &lt;Button Command="{x:Static NavigationCommands.PreviousPage}" CommandTarget="{Binding ElementName=PageViewer}" Content="&amp;lt; Previous" /&gt; &lt;Button Command="{x:Static NavigationCommands.NextPage}" CommandTarget="{Binding ElementName=PageViewer}" Content="Next &amp;gt;" /&gt; &lt;Separator /&gt; &lt;l:ToolBarButtonGroup ItemsSource="{Binding Source={StaticResource ViewStyles}}" SelectedItem="{Binding ViewType, ElementName=UserControl}" IsSynchronizedWithCurrentItem="True" &gt; &lt;l:ToolBarButtonGroup.ItemTemplate&gt; &lt;DataTemplate&gt; &lt;StackPanel Orientation="Horizontal" ToolTip="{Binding}" SnapsToDevicePixels="True"&gt; &lt;Image Source="../Images/actual.png" Visibility="{Binding Converter={StaticResource EnumVisibilityConverter}, ConverterParameter=Actual}" /&gt; &lt;Image Source="../Images/fit.png" Visibility="{Binding Converter={StaticResource EnumVisibilityConverter}, ConverterParameter=Fit}" /&gt; &lt;Image Source="../Images/wide.png" Visibility="{Binding Converter={StaticResource EnumVisibilityConverter}, ConverterParameter=Wide}" /&gt; &lt;/StackPanel&gt; &lt;/DataTemplate&gt; &lt;/l:ToolBarButtonGroup.ItemTemplate&gt; &lt;/l:ToolBarButtonGroup&gt; &lt;/ToolBar&gt; &lt;ScrollViewer x:Name="ScrollViewer" HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Disabled"&gt; &lt;Border BorderBrush="Black" BorderThickness="1" HorizontalAlignment="Center" VerticalAlignment="Top" Background="White" Margin="10"&gt; &lt;Viewbox x:Name="Viewbox" Stretch="Uniform"&gt; &lt;FlowDocumentPageViewer x:Name="PageViewer" Document="{Binding Document, ElementName=UserControl}" Zoom="100" MinZoom="20" MaxZoom="200"&gt; &lt;FlowDocumentPageViewer.Template&gt; &lt;ControlTemplate TargetType="{x:Type FlowDocumentPageViewer}"&gt; &lt;AdornerDecorator&gt; &lt;DocumentPageView FlowDocumentPageViewer.IsMasterPage="True" /&gt; &lt;/AdornerDecorator&gt; &lt;/ControlTemplate&gt; &lt;/FlowDocumentPageViewer.Template&gt; &lt;/FlowDocumentPageViewer&gt; &lt;/Viewbox&gt; &lt;/Border&gt; &lt;/ScrollViewer&gt; &lt;/DockPanel&gt; &lt;/ControlTemplate&gt; &lt;/Control.Template&gt; &lt;/Control&gt; </code></pre> <p>Where you might put such a control is up to you (and your app) of course, but our app has a similar behavior to the typical Office app where you can either print directly or preview (which shows the above interface) and print from there.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload