title: Setting Event Handler in WPF code behind
body: <p>My WPF program uses a third party map package which has a WPF map control.  My program needs to be able to run on a system which does not have this software installed, and it needs to be smart enough to recognize when the software is installed and use it.  This means that I can't include any XAML for the map control in my form's XAML file or XAML parse exceptions are thrown.</p>
  
  <p>I have a technique for determining if the software is installed.  In my program's initialization code, I set a property of the Application object called <code>MapsAreInstalled</code> to true if the mapping software is installed, and I set it to false if it is not.</p>
  
  <p>In my form, which is a UserControl, I've added an override of the OnApplyTemplate method.  This checks the value of the <code>MapsAreInstalled</code> property and creates a new map control if the value is true.  Here's the XAML that I was using to create this control before it became obvious that I had to change my approach:</p>
  
  <pre><code>&lt;telogis:MapControl ButtonBase.Click="CarImage_Click"
                      Canvas.Left="0"
                      Canvas.Top="0"
                      Center="41.366674544084,-73.6112966322899"
                      DragBehavior="None"
                      Heading="0"
                      Height="{Binding ElementName=ChannelCanvas, Path=ActualHeight}"
                      MapQuality="Perfect"
                      Name="ReadMap"
                      Perspective="TwoD"
                      RenderLabels="True"
                      UiEnable="True"
                      Width="{Binding ElementName=ChannelCanvas, Path=ActualWidth}"
                      Zoom="50" /&gt;
  </code></pre>
  
  <p>I know how to initialize all of these properties in the code behind EXCEPT the <code>ButtonBase.Click</code> event handler.  How do I set this up in the code-behind?</p>
  
  <p>Tony</p>