Share via


How to: Data-Bind DocumentViewer's Zoom Property to a TextBox

This example shows how to bind the Zoom property of a DocumentViewer to a text control, using Extensible Application Markup Language (XAML).

Example

<Window x:Class="SDKSample.Window1"
        xmlns="https://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="https://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>

Task Remarks

  • In this example, any changes to the value of Zoom are immediately reflected in the data-bound TextBox.

  • This example uses a "simple" binding declaration to bind the value of Zoom to the Text property of a TextBox.

  • The ElementID clause in the binding declaration refers to the Name of the source element, which in this case is "dvZoomSource".

  • The Path clause in the binding declaration names the source property, which in this case is Zoom.

  • The Mode clause in the binding declaration specifies that this is a one-way data binding; updates to the source value of Zoom are reflected in the target TextBox, but changes to the contents of the TextBox do not change the value of Zoom.

See Also

Concepts

Data Binding Overview
Binding Declarations Overview