title: Getting Value from ViewModel through DataContext WITHOUT Binding?
body: <p>New to WPF. I am creating UserControls that need read access to the ViewModel state to do their thing. I currently use the following technique:</p>
  
  <pre class="lang-cs prettyprint-override"><code>public partial class ControlBar : UserControl
  {
  
      private static readonly DependencyProperty URLProperty =
          DependencyProperty.Register("URL", typeof(string), typeof(ControlBar),
          new UIPropertyMetadata(null));
  
      public ControlBar()
      {
          InitializeComponent();
  
          SetBinding(URLProperty, "CurrentPage.URL");
  
          Pin.Click += Pin_Click;       
      }
  
      private void Pin_Click(object sender, RoutedEventArgs e)
      {
          var URL = (string)GetValue(URLProperty);
  
      }
  }
  </code></pre>
  
  <p>Is this the correct way and is it not overkill to set up a long-term binding for each variable I need access to? Or can you do something like:</p>
  
  <pre><code>GetValue(new Path("CurrentPage.URL..... 
  </code></pre>
  
  <p>I made up the above obviously. </p>
  
  <p>Thanks!</p>