title: Why does this added UI button's event not get called?
body: <p>In developing a mod for Cities: Skylines, I have run across a problem.</p>
  
  <p>Most of my code, as far as I can tell, works fine - but so far, I haven't got to test it. This is because it should all get called in sequence when a button I have added to the UI gets clicked. The click event on this button is not calling the handler I've assigned to it.</p>
  
  <p>This is where I create the button:</p>
  
  <pre><code>public class LoadingExtension : LoadingExtensionBase
  {
      public override void OnLevelLoaded(LoadMode mode)
      {
          Debug.LogDebugMessage("Adding 'Generate City Report' button to UI");
  
          // Get the UIView object. This seems to be the top-level object for most
          // of the UI.
          var uiView = UIView.GetAView();
  
          // Add a new button to the view.
          var button = (UIButton)uiView.AddUIComponent(typeof(UIButton));
  
          // Set the text to show on the button.
          button.text = "Generate City Report";
  
          // Set the button dimensions.
          button.width = 250;
          button.height = 30;
  
          // Style the button to look like a menu button.
          button.normalBgSprite = "ButtonMenu";
          button.disabledBgSprite = "ButtonMenuDisabled";
          button.hoveredBgSprite = "ButtonMenuHovered";
          button.focusedBgSprite = "ButtonMenuFocused";
          button.pressedBgSprite = "ButtonMenuPressed";
          button.textColor = new Color32(255, 255, 255, 255);
          button.disabledTextColor = new Color32(7, 7, 7, 255);
          button.hoveredTextColor = new Color32(7, 132, 255, 255);
          button.focusedTextColor = new Color32(255, 255, 255, 255);
          button.pressedTextColor = new Color32(30, 30, 44, 255);
  
          // Enable button sounds.
          button.playAudioEvents = true;
  
          // Place the button.
          button.transformPosition = new Vector3(-1.0f, 0.97f);
  
          // Respond to button click.
          // NOT GETTING CALLED
          button.eventClick += ButtonClick;
      }
  
      public void ButtonClick(UIComponent component, UIMouseEventParameter eventParam)
      {
          Debug.LogWarningMessage("HIGH LOGIC: Beginning report generation.");
          string now = DateTime.Now.ToFileTime().ToString();
          string filepath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
          string filename = filepath + "\\CityReport-" + now + ".xlsx";
          Output fileCreator = new Output(filename);
          fileCreator.GenerateReport();
      }
  }
  </code></pre>
  
  <p>According to the <a href="http://skylines-modding-docs.readthedocs.org/en/latest/modding/Development/How-to-Use-ColossalFramework.UI.html" rel="noreferrer">documentation</a> I've been following, using</p>
  
  <pre><code>button.eventClick += ButtonClick;
  </code></pre>
  
  <p>should add <code>ButtonClick</code> as the click handler for the button. However, clicking on the button does nothing. The debug message at the start of the handler (the "HIGH LOGIC" message) doesn't get displayed (note: the earlier debug message about adding the button to the UI does). No error messages are displayed either in the game's debug panel or in VS.</p>
  
  <p>I have also tried using <code>new MouseEventHandler(ButtonClick)</code>, since the VS inline documentation tells me that the type of <code>eventClick</code> is <code>MouseEventHandler</code>. This doesn't show any errors in VS or the game, but doesn't work either.</p>
  
  <p>(Note: there <em>is</em> <a href="http://www.skylineswiki.com/Modding_API" rel="noreferrer">official documentation</a>, but it's next to useless.)</p>
  
  <p>Does anyone here have experience with the C:S API? Why is this event not getting called?</p>