title: Conditionally auto-click button in MVVM using xaml
body: <p>I am writing an application based on MVVM architecture. The application has a Wizard like workflow. In couple of pages (views) in my application, I need a button to be auto-clicked when a certain condition is satisfied. The views are tied together using the root Wizard view model which has a ClickNextBtn command that is tied to the Next button in the root Wizard view. So, I need something like in the root Wizard view:</p>
  
  <pre><code>&lt;DataTrigger Binding="{Binding Path=CanAutoClickNext}" Value="True"&gt;
      &lt;Setter Property="ClickBtn" Value="true" /&gt;
  &lt;/DataTrigger&gt;
  </code></pre>
  
  <p>The property in the above sample is meaningless, but hopefully it helps convey what I am trying to do.</p>
  
  <p>The CanAutoClickNext bool property is available off of the Wizard view model.</p>
  
  <p>On one of the views where I need the Next button auto-clicked, I tried passing the WizardViewModel as an argument to its corresponding view model's constructor when it is first instantiated in the root wizard view model, and then calling the ClickNextBtn off of it in a method therein later when the view is actually loaded. But that did not work, not surprisingly.</p>
  
  <p>I know how to programmatically click a wpf button, but getting it all tied together in the framework I have is proving to a big challenge. Any feedback is appreciated.</p>
  
  <p><strong>UPDATE:</strong>
  I ended up rewriting the UI design pattern (still MVVM) so that now instead of having to having to move to a next page automatically, the state within a page changes and a different set of controls become active. Users are then prompted to click next.</p>