title: How to bind button to method in VB.net
body: <p>I am doing some research online to find out how to do this but I have fallen short so far. I think there is a knowledge gap that I have to overcome.</p>
  
  <p>I have a wpf button that when clicked would execute a sub inside of the object it is bound too.</p>
  
  <p>I would like to know how to get the button to execute exampleObject.displayMessage().</p>
  
  <h1>VB.NET</h1>
  
  <pre><code>Private Sub Window_Loaded(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles MyBase.Loaded
  
          Dim exObject As New exampleObject
          Grid1.DataContext = exObject 
  
  End Sub
  
  Public Class exampleObject
      Public ReadOnly Property testMessage As String
          Get
              Return "this is a test"
          End Get
      End Property
  
      Public Sub displayMessage()
          MsgBox(testMessage)
      End Sub
  End Class
  </code></pre>
  
  <h1>WPF</h1>
  
  <pre><code>&lt;Window x:Class="Window1"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      Title="Window1" Height="300" Width="300"&gt;
      &lt;Grid&gt;
          &lt;Grid Name="Grid1"&gt;
              &lt;Button Content="Button" Name="Button1"/&gt;
          &lt;/Grid&gt;
      &lt;/Grid&gt;
  &lt;/Window&gt;
  </code></pre>