Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

How to reduce size of an XPSdocument to fit (or scroll) in a DocumentViewer

$
0
0

I am having problems with the DocumentViewer and would appreciate any help that can be offered.

I have it successfully to the point where the drawing (.dwfx) is downloaded from a HttpWebRequest to a MemoryStream, converted to an xpsDocument and then the FixedDocumentSequence is bound to the DocumentViewer.Document. The problem is that the document appears really huge and the user has to scroll forever to see the whole thing. Even if I set the horizontal/vertical scrollbars to true, instead of auto, they disappear when I use the FitToHeightCommand or FitToWidthCommand. This would be ok if it didn't also add a new 50px margin on the left which, without that horizontal scrollbar, leaves the rest of the image unviewable.

I have tried restyling the DocumentViewer, but I think the problem may really be the need to re-size the actual document (original is some 3300px wide) and I haven't been able to successfully do that.

Here is the most pertinent part of what I have so far. The DrawingFDS property is the FixedDocumentSequence bound to the View. Thanks in advance for any hints/suggestions.

the Binding source:

private void FindPartDrawing(string partNumber) { DrawingFDS = new FixedDocumentSequence(); string drawingFile = GetVaultDrawingPath(partNumber); DrawingUri = new Uri(drawingFile); Stream stream = new MemoryStream(); DownloadDrawing(DrawingUri, ref stream); Package package = Package.Open(stream); if (PackageStore.GetPackage(DrawingUri) != null) PackageStore.RemovePackage(DrawingUri); PackageStore.AddPackage(DrawingUri, package); var xpsDocument = new XpsDocument(package, CompressionOption.SuperFast, drawingFile); DrawingFDS = xpsDocument.GetFixedDocumentSequence(); }

The XAML:

<DocumentViewer Name="drawingViewer" Style="{StaticResource DocumentViewerStyle1}" Document="{Binding DrawingFDS}" Height="598" MaxPagesAcross="1" />


<Style x:Key="DocumentViewerStyle1" BasedOn="{x:Null}" TargetType="{x:Type DocumentViewer}"><Setter Property="HorizontalContentAlignment" Value="Left"/><Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.WindowTextBrushKey}}"/><Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"/><Setter Property="FocusVisualStyle" Value="{x:Null}"/><Setter Property="Template"><Setter.Value><ControlTemplate TargetType="DocumentViewer"><Border BorderThickness="{TemplateBinding BorderThickness}"
                            BorderBrush="{TemplateBinding BorderBrush}"
                            Focusable="False"><Grid KeyboardNavigation.TabNavigation="Local"><Grid.Background><SolidColorBrush Color="White" /></Grid.Background><Grid.RowDefinitions><RowDefinition Height="Auto" /><RowDefinition Height="*" /><RowDefinition Height="Auto" /></Grid.RowDefinitions><ToolBar ToolBarTray.IsLocked="True" KeyboardNavigation.TabNavigation="Continue"><Button Command="NavigationCommands.IncreaseZoom" CommandTarget="{Binding RelativeSource={RelativeSource TemplatedParent}}" Content="Zoom In" /><Separator /><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" /><Separator /><Button Command="DocumentViewer.FitToWidthCommand" CommandTarget="{Binding RelativeSource={RelativeSource TemplatedParent}}" Content="Fit to Width" /><Separator /><Button Command="DocumentViewer.FitToHeightCommand" CommandTarget="{Binding RelativeSource={RelativeSource TemplatedParent}}" Content="Fit to Height" /></ToolBar><ScrollViewer Grid.Row="1"
                                    CanContentScroll="True"
                                    HorizontalScrollBarVisibility="Visible"
                                    x:Name="PART_ContentHost"
                                    IsTabStop="true"><ScrollViewer.Background><LinearGradientBrush EndPoint="0.5,1"
                                            StartPoint="0.5,0"><GradientStop Color="White"
                                                Offset="0" /><GradientStop Color="LightGray"
                                                Offset="2" /></LinearGradientBrush></ScrollViewer.Background></ScrollViewer><!--<ContentControl Grid.Row="2"
                                    x:Name="PART_FindToolBarHost"/>--></Grid></Border></ControlTemplate></Setter.Value></Setter></Style>



Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>