title: Custom control toolbar need to invoke methods on my VM. How to do that?
body: <p>Here is my question. I have <code>UserControl</code> that wraps group of buttons and it looks like this: (I show 2 buttons to illustrate what it is)</p>
  
  <pre><code>&lt;Button Content="Cancel"
          IsEnabled="{Binding State, Converter={StaticResource CancelEnabledConverter}}"&gt;
      &lt;i:Interaction.Triggers&gt;
          &lt;i:EventTrigger EventName="Click"&gt;
              &lt;ei:CallMethodAction MethodName="Cancel" TargetObject="{Binding}"/&gt;
          &lt;/i:EventTrigger&gt;
      &lt;/i:Interaction.Triggers&gt;
  &lt;/Button&gt;
  
  &lt;Button Content="Delete" 
          IsEnabled="{Binding State, Converter={StaticResource DeleteEnabledConverter}}"&gt;
      &lt;i:Interaction.Triggers&gt;
          &lt;i:EventTrigger EventName="Click"&gt;
              &lt;ei:CallMethodAction MethodName="Delete" TargetObject="{Binding}"/&gt;
          &lt;/i:EventTrigger&gt;
      &lt;/i:Interaction.Triggers&gt;
  &lt;/Button&gt;
  </code></pre>
  
  <p>Now, when I place this <code>UserControl</code> on my view - I go by convention and create <code>Cancel</code> and <code>Delete</code> methods on my VM. So, view's XAML looks clean.</p>
  
  <p>I want to create custom control that will have same functionality. Inside control I will have to handle <code>onClick</code> events for buttons and would like to call methods on VM just like it works now. What my code going to look like? I guess I need to access <code>DataContext</code> programmatically and call method by name somehow. I envision using control like so:</p>
  
  <pre><code>&lt;myToolBar Mode="SaveExitDelete" /&gt;
  </code></pre>
  
  <p>So, this will be nice and short. But <code>myToolBar</code> will show 3 buttons and those buttons will call 3 methods(named by convention) on DataContext.</p>
  
  <p>Any pointers?</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Main question is to how programmaticaly BIND command or method to button. I understand how commanding works, I'm using PRISM and it's got built-in DelegateCommand that I can use. I don't know how to create binding programmaticaly when I know Method name or command name.</p>
  
  <p>Here is how I can see it working:</p>
  
  <p><code>var button = new DitatToolbarButton();
  button.Caption = "Cancel &amp;\nExit";
  button.Icon = new BitmapImage(new Uri("img_btn_cancel.png", UriKind.Relative));
  button.Command = Binding("CancelCommand");</code></p>
  
  <p>Obviously 3rd line is wrong but this is what I want. I want to be able to hardcode string that will contain name of command that I will expect VM to have.</p>