title: How do I bind a WPF control to a VB.net property?
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/5533803/data-binding-wpf-property-to-variable">Data Binding WPF Property to Variable</a>  </p>
  </blockquote>
  
  
  
  <p>How would I bind my module1 property to my WPF TextBox1?</p>
  
  <p>WPF code:</p>
  
  <pre><code>&lt;Window x:Class="MainWindow"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      Title="MainWindow" Height="350" Width="525"&gt;
      &lt;Grid&gt;
          &lt;TextBox Height="23" HorizontalAlignment="Left" Margin="210,146,0,0" Name="TextBox1" VerticalAlignment="Top" Width="120" /&gt;
      &lt;/Grid&gt;
  &lt;/Window&gt;
  </code></pre>
  
  <p>VB.net code:</p>
  
  <pre><code>Module Module1
      ReadOnly Property tbBinding As String
          Get
              Return "Success!"
          End Get
      End Property
  End Module
  </code></pre>
  
  <p>Below is code that I have been working on based on the feed back I have been getting and the reading I have been doing.
  /#######Current code in progres (trying with a class instead of a module)#######/</p>
  
  <p>XAML:</p>
  
  <pre><code>&lt;Window x:Class="MainWindow"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      Title="MainWindow" Height="350" Width="525"&gt;
      &lt;Grid DataContext="Class1"&gt;
          &lt;TextBox Height="23" HorizontalAlignment="Left" Margin="210,146,0,0" Name="TextBox1" VerticalAlignment="Top" Width="120" Text="{Binding Path=tbBinding2}"/&gt;
          &lt;Button Content="Button" Height="23" HorizontalAlignment="Left" Margin="192,74,0,0" Name="Button1" VerticalAlignment="Top" Width="75" /&gt;
      &lt;/Grid&gt;
  &lt;/Window&gt;
  </code></pre>
  
  <p>Class1:</p>
  
  <pre><code>Imports System.ComponentModel
  
  Public Class Class1
      Implements INotifyPropertyChanged
  
      Public Event PropertyChanged As PropertyChangedEventHandler Implements INotifyPropertyChanged.PropertyChanged
  
      Private Sub NotifyPropertyChanged(ByVal info As String)
          RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(info))
      End Sub
  
      Dim varField As String = String.Empty
  
      Public Property tbBinding2 As String
          Get
              Return varField
          End Get
  
          Set(value As String)
              varField = value
              NotifyPropertyChanged("tbBinding2")
          End Set
      End Property
  End Class
  </code></pre>
  
  <p>MainWindow:</p>
  
  <pre><code>Class MainWindow 
  
      Private Sub Button1_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles Button1.Click
          Dim myClass1 As New Class1
          myClass1.tbBinding2 = "Success!"
      End Sub
  End Class
  </code></pre>