title: Writing back a dependency property value to the view model in two-way binding
body: <p>I'm implementing a wpf control that provides some common binding between xaml and Google Maps running in a web browser. Currently, the bindings are one-way and are working fine. </p>
  
  <p>What I need to do next is write back a value to the view model when two-way binding is specified. The property I'm starting with is the Google Map's zoom. When it's changed in the browser I can run js on the page that calls back to my C# code with the new zoom level. </p>
  
  <p>What's the correct way to offer this new value to the DP such thas it will update the view model's zoom level if a two-way binding was selected?</p>
  
  <p>My current code for the the zoom level DP:</p>
  
  <pre><code>#region ZoomProperty
  
      //Called from the web page
      private JSValue MapZoom_OnMapZoomChanged(JSValue[] arguments) {
          string zoom = arguments[0];
  
          //where do I set the zoom so that the view model bound property is updated?
          return null;
      }
  
  public static readonly DependencyProperty ZoomProperty =
      DependencyProperty.Register("Zoom", typeof(string), typeof(GoogleMap), new FrameworkPropertyMetadata(string.Empty, OnZoomPropertyChanged), OnZoomPropertyValidate);
  
  public string Zoom {
      get { return (string)GetValue(ZoomProperty); }
      set { SetValue(ZoomProperty, value); }
  }
  
  private static bool OnZoomPropertyValidate(object value) {
      return value is string;
  }
  
  private static void OnZoomPropertyChanged(DependencyObject source, DependencyPropertyChangedEventArgs e) {
      GoogleMap control = source as GoogleMap;
      control.SetZoom(e.NewValue.ToString());
  }
  
  private string zoom;
  public void SetZoom(string value) {
      if (!googleMapPageReady) {
          zoom = value;
          return;
      }
  
      webControl.ExecuteJavascript(string.Format("setZoom({0})", zoom));
  }
  
  #endregion
  </code></pre>