title: Invoking multiple command targets from a single command source
body: <p>i need to invoke multiple instances of a command </p>
  
  <p>for this example i'll take 2 controls 'A' and 'B'</p>
  
  <p>'A' would be the Invoker and 'B' the invokie  and there are multiple instances of 'B' </p>
  
  <p><strong>the Controls :</strong></p>
  
  <pre><code> public class A : Control 
   {
       public A()
       {}
  
       public ICommand OnACommand   
       {
          get { return (ICommand)GetValue(OnAProperty); }
          set { SetValue(OnACommandProperty, value); }
       }
  
      public static readonly DependencyProperty OnACommandProperty =
          DependencyProperty.Register("OnACommand", typeof(ICommand), typeof(A), new UIPropertyMetadata(null));
  
       public bool Something   
       {
          get { return (bool)GetValue(SomethingProperty); }
          set { SetValue(SomethingProperty, value); }
       }
  
      public static readonly DependencyProperty SomethingProperty=
          DependencyProperty.Register("Something", typeof(bool), typeof(A), new UIPropertyMetadata(false,OnSometingPropertyChanged));
  
      private static void  OnSometingPropertyChanged(...)
      {
          ... 
          OnACommand.Execute(this.Value);
      }                  
   }
  
  
   public class B : Control 
   {
       public B(){ }
  
       public ICommand OnBCommand   
       {
          get { return (ICommand)GetValue(OnBCommandProperty); }
          set { SetValue(OnBCommandProperty, value); }
       }
  
      public static readonly DependencyProperty OnBCommandProperty =
          DependencyProperty.Register("OnBCommand", typeof(ICommand), typeof(B), new UIPropertyMetadata(null));              
   }
  </code></pre>
  
  <p><strong>the Binding :</strong> </p>
  
  <pre><code>   &lt;local:B  x:Name="B1" OnBCommand="{Binding ElementName=A1 , Path=OnACommand /&gt;
     &lt;local:B  x:Name="B2" OnBCommand="{Binding ElementName=A1 , Path=OnACommand /&gt;   
     &lt;local:A  x:Name="A1"  /&gt;   
  </code></pre>
  
  <p><strong>what i need is for all the B Commands Bound to that A command to Execute when Executing OnACommand.</strong></p>
  
  <p>the only approach which i would think to work is if i <em>implemented the Command inside B</em> and <em>bound it OneWayTosource</em> , but than  only the last one the Bind to A would be the B which would get Executed .</p>
  
  <pre><code>  public B()
    {
         OnBCommand = new RelayCommand&lt;int&gt; 
                      (
                          value =&gt; { this.Value = value ....}
                      );
    }
  
     &lt;local:B  x:Name="B1" 
               OnBCommand="{Binding ElementName=A1,Path=OnACommand,Mode=OneWayToSource /&gt;
     &lt;local:B  x:Name="B2" 
               OnBCommand="{Binding ElementName=A1,Path=OnACommand,Mode=OneWayToSource /&gt;   
     &lt;local:A  x:Name="A1"  /&gt;   
  </code></pre>
  
  <p>if i bound it any other way like OneWay i need  to implement the Command in A and B has no idea 
  that it was even executed, unless it's possible to some how acknowledge the execution from a delegate  within B ..       </p>
  
  <p>so to summarize i need to execute multiple targets from one source.</p>
  
  <p>in addition i might point out that i solved this using a regular .net event which i declared in 'A1' 
  and Subscribed all the B's to,but since this is WPF written in MVVM i'm looking for the MVVM Style Way of doing this , using Commands . </p>
  
  <p>thanks in advance. </p>