title: wpf xaml calling a method on the current object
body: <p>Im attempting to bind to the output of a method. Now I've seen examples of this using <code>ObjectDataProvider</code> However the problem with this is ObjectDataProvider creates a new instance of the object to call the method. Where I need the method called on the current object instance. I'm currently trying to get a converter to work.    </p>
  
  <p>Setup:</p>
  
  <pre><code>Class Entity
  {
     private Dictionary&lt;String, Object&gt; properties;
  
     public object getProperty(string property)
    {
        //error checking and what not performed here
       return this.properties[property];
    }
  }
  </code></pre>
  
  <p>My attempt at the XAML</p>
  
  <pre><code>     &lt;local:PropertyConverter x:Key="myPropertyConverter"/&gt;
        &lt;TextBlock Name="textBox2"&gt;
            &lt;TextBlock.Text&gt;
              &lt;MultiBinding Converter="{StaticResource myPropertyConverter}"
                            ConverterParameter="Image" &gt;
                &lt;Binding Path="RelativeSource.Self" /&gt; &lt;!--this doesnt work--&gt;
              &lt;/MultiBinding&gt;
            &lt;/TextBlock.Text&gt;
          &lt;/TextBlock&gt;
  </code></pre>
  
  <p>my code behind</p>
  
  <pre><code>public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
  {
      string param = (string)parameter;
      var methodInfo = values[0].GetType().GetMethod("getProperty", new Type[0]);
      if (methodInfo == null)
          return null;
      return methodInfo.Invoke(values[0], new string[] { param });               
  }
  
  public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
  {
      throw new NotSupportedException("PropertyConverter can only be used for one way conversion.");
  }
  </code></pre>
  
  <p>My problem is that I cant seem to pass the current Entity into the converter. So When i try to use reflection to get the getProperty method I have nothing to operate on</p>
  
  <p>thanks, steph</p>