title: adding custom routed event of user control to xaml of a window in wpf
body: <p>I am little new to Command binding so this might be a trivial question to many. I know that we can add Command bindings in xaml of a window and give its correspondng property in viewmodel. This viewmodel will be given to the DataContext of the window. Something like the following</p>
  
  <p>--app.xaml.cs</p>
  
  <pre>mainWindow.DataContext = viewModel;</pre>
  
  <p>-- xaml</p>
  
  <pre>lt;Button Grid.Row="1" HorizontalAlignment="Right" Margin="0,3,18,3" Name="button1" Width="110" 
                  Command="{Binding LoadCommand}"&gt;_Load&lt;/Button&gt;</pre>
  
  <p>-- viewmodel</p>
  
  <pre>/// &lt;summary&gt;
          /// Gets the load command.
          /// &lt;/summary&gt;
          /// &lt;value&gt;The load command.&lt;/value&gt;
          public ICommand LoadCommand
          {
              get
              {
                  if (m_LoadCommand == null)
                  {
                      m_LoadCommand = new RelayCommand(param =&gt; CanLoad(), param =&gt; Load());
                  }
  
                  return m_LoadCommand;
              }
          }</pre>
  
  <p>Here the relaycommand is a class which implements ICommand interface. CanLoad() and Load() are the methods which will get executed for canexecute and execute action of the relaycommand respectively. This is the click event of the button which is handled. </p>
  
  <p>I have a user control which has a custom routedevent registered in it and the user control is then used on a window. I am currently adding the event handler explicitly in code.</p>
  
  <pre>//hook up event listeners on the actual UserControl instance
              this.ucCustomEvent1.CustomClick += new RoutedEventHandler(ucCustomEvent_CustomClick);
              //hook up event listeners on the main window (Window1)
              this.AddHandler(UserControlThatCreatesEvent.CustomClickEvent, new RoutedEventHandler(ucCustomEvent_CustomClick));</pre>
  
  <p>I dont want to hook up the routedevent explicitly in code but in the xaml in the similar way as in the button example. I have uploaded the working sample code <a href="http://share1t.com/ezmzti" rel="nofollow noreferrer">here</a> for your perusal.</p>