|
|
|
Questions and Answers for Controls Document Viewer.
|
69. Controls DocumentViewer
|
| 69.1 How can I
replace the style of a DocumentViewer ?
|
| 69.2 How can I
extend the style of a DocumentViewer ?
|
| 69.3 How can I
DataBind DocumentViewer's Zoom Property to a TextBox ?
|
| 69.4 How to load
an XPS document into the DocumentViewer?
|
69.1 How can I replace the style of a DocumentViewer ?
|
|
n a typical WPF application, it contains many elements. These elements exist in
an element tree relationship with each other. A routed event is a type of event
that can invoke handlers on multiple listeners in an element tree, rather than
just on the object that raised the event.
Routing events uses one of the three following strategies:
Bubbling: Event handlers on the event source are invoked.s
Direct: Only the source element itself is given the opportunity to invoke
handlers in response.
Tunneling: Initially, event handlers at the element tree root are invoked.
|
69.2 How can I extend the style of a DocumentViewer ?
|
|
The following style uses the "BasedOn" attribute to extend the default
DocumentViewer style. In this case, the example style simply mirrors the
background gradient used by the default toolbar style and applies it to the
background of the content display area.
|
[XAML]
<Window x:Class="SDKSample.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Window.Resources>
<Style
x:Key="MyDVStyleExtend"
BasedOn="{StaticResource {x:Type DocumentViewer}}"
TargetType="{x:Type DocumentViewer}">
<Setter Property="Background">
<Setter.Value>
<LinearGradientBrush StartPoint="0.5,0"
EndPoint="0.5,1">
<GradientStop Offset="0.0" Color="#CC99CCFF" />
<GradientStop Offset="1.0" Color="White" />
</LinearGradientBrush>
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
<Grid>
<DocumentViewer Style="{StaticResource MyDVStyleExtend}"
Name="MyDocumentViewer"/>
</Grid>
</Window>
|
69.3 How can I DataBind DocumentViewer's Zoom Property to a TextBox ?
|
|
This example shows how to bind the "Zoom" property of a DocumentViewer to a
textbox.
|
[XAML]
<Window x:Class="SDKSample.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<DocumentViewer Name="dvZoomSource" Grid.Row="0" />
<TextBox Grid.Row="1"
Text="{Binding ElementName=dvZoomSource, Path=Zoom,
Mode=OneWay}" />
</Grid>
</Window>
|
69.4 How to load an XPS document into the DocumentViewer?
|
|
XPS documents can be easily loaded into the documentviewer.
Here's the code snippet.
|
[XAML]
<DocumentViewer Name="documentViewer" />
|
|
|
[C#] XpsDocument xpsDocument = new XpsDocument("sample.xps",
FileAccess.Read); documentViewer.Document = xpsDocument; $$$$
|
|