共用方式為


HOW TO:將 DocumentViewer 之 Zoom 屬性的資料繫結至 TextBox

更新:2007 年 11 月

這個範例顯示如何使用可延伸標記語言 (XAML) 將 DocumentViewerZoom 屬性繫結至文字控制項。

範例

<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>

工作備註

  • 在這個範例中,Zoom 值的所有變更都會立即反映於資料繫結的 TextBox 中。

  • 這個範例使用「簡單的」繫結宣告,將 Zoom 繫結至 TextBoxText 屬性。

  • 繫結宣告中的 ElementID 子句會參考來源項目的 Name,在這個案例中為 "dvZoomSource"。

  • 繫結宣告中的 Path 子句會替來源屬性命名,在這個案例中為 Zoom

  • 繫結宣告中的 Mode 子句會指定這是單向資料繫結 (Data Binding)。Zoom 來源值的更新會反映在目標 TextBox 中,但 TextBox 的內容變更並不會變更 Zoom 的值。

請參閱

概念

資料繫結概觀

繫結宣告概觀