title: WPF Binding and Dynamically Assigning StringFormat Property
body: <p>I have a form that is generated based on several DataTemplate elements. One of the DataTemplate elements creates a TextBox out of a class that looks like this:</p>
  
  <pre><code>public class MyTextBoxClass
  {
     public object Value { get;set;}
     //other properties left out for brevity's sake
     public string FormatString { get;set;}
  }
  </code></pre>
  
  <p>I need a way to "bind" the value in the FormatString property to the "StringFormat" property of the binding. So far I have:</p>
  
  <pre><code>&lt;DataTemplate DataType="{x:Type vm:MyTextBoxClass}"&gt;
   &lt;TextBox Text="{Binding Path=Value, StringFormat={Binding Path=FormatString}" /&gt;
  &lt;/DataTemplate&gt;
  </code></pre>
  
  <p>However, since StringFormat isn't a dependency property, I cannot bind to it.</p>
  
  <p>My next thought was to create a value converter and pass the FormatString property's value in on the ConverterParameter, but I ran into the same problem -- ConverterParameter isn't a DependencyProperty.</p>
  
  <p>So, now I turn to you, SO. How do I dynamically set the StringFormat of a binding; more specifically, on a TextBox?</p>
  
  <p>I would prefer to let XAML do the work for me so I can avoid playing with code-behind. I'm using the MVVM pattern and would like to keep the boundaries between view-model and view as un-blurred as possible.</p>
  
  <p>Thanks!</p>