title: BarButtonItems and BarSubItems on Bound RibbonControl
body: <p>I am developing a WPF application using DevExpress controls, such as the Ribbon control. I want to be able to place buttons on the ribbon dynamically. I would like to be able to support both regular buttons and drop-down buttons.</p>
  
  <p>I was thinking something similar to below.</p>
  
  <p><strong>WPF View:</strong></p>
  
  <pre><code>&lt;UserControl.Resources&gt;
      &lt;DataTemplate x:Key="RibbonCommandTemplate"&gt;
          &lt;ContentControl&gt;
              &lt;dxb:BarButtonItem RibbonStyle="All" Content="{Binding Caption}"
                                 Command="{Binding (dxr:RibbonControl.Ribbon).DataContext.MenuExecuteCommand,
                                           RelativeSource={RelativeSource Self}}" 
                                 CommandParameter="{Binding}" /&gt;
          &lt;/ContentControl&gt;
      &lt;/DataTemplate&gt;
  &lt;/UserControl.Resources&gt;
  
  &lt;Grid&gt;
      &lt;DockPanel&gt;
          &lt;dxr:RibbonControl DockPanel.Dock="Top" RibbonStyle="Office2010"&gt;
              &lt;dxr:RibbonDefaultPageCategory&gt;
                  &lt;dxr:RibbonPage Caption="Home"&gt;
                      &lt;dxr:RibbonPageGroup Caption="Dynamic Commands" 
                                           ItemLinksSource="{Binding DynamicCommands}"
                                           ItemTemplate="{StaticResource RibbonCommandTemplate}" /&gt;
                  &lt;/dxr:RibbonPage&gt;
              &lt;/dxr:RibbonDefaultPageCategory&gt;
          &lt;/dxr:RibbonControl&gt;
          &lt;Grid/&gt;
      &lt;/DockPanel&gt;
  &lt;/Grid&gt;
  </code></pre>
  
  <p><strong>View Model:</strong></p>
  
  <pre><code>public class RibbonCommand
  {
      public string Caption { get; set; }
      public int CommandCode { get; set; }
  
      public ObservableCollection&lt;RibbonCommand&gt; SubItems { get; set; }
  
      public bool HasSubItems
      {
          get
          {
              if (SubItems != null)
                  return (SubItems.Count &gt; 0);
              else
                  return false;
          }
      }
  }
  
  [POCOViewModel]
  public class MainViewModel
  {
      public ObservableCollection&lt;RibbonCommand&gt; DynamicCommands { get; set; }
  
      public MainViewModel()
      {
          DynamicCommands = new ObservableCollection&lt;RibbonCommand&gt;();
  
          // Regular buttons.
          DynamicCommands.Add(new RibbonCommand() { Caption = "Button 1", CommandCode = 1 });
          DynamicCommands.Add(new RibbonCommand() { Caption = "Button 2", CommandCode = 2 });
  
          // Drop-down button.
          RibbonCommand dropDownCommand = new RibbonCommand() { Caption = "Drop-Down", CommandCode = 3 };
          dropDownCommand.SubItems = new ObservableCollection&lt;RibbonCommand&gt;();
          dropDownCommand.SubItems.Add(new RibbonCommand() { Caption = "Sub-Item 1", CommandCode = 31 });
          dropDownCommand.SubItems.Add(new RibbonCommand() { Caption = "Sub-Item 2", CommandCode = 32 });
          dropDownCommand.SubItems.Add(new RibbonCommand() { Caption = "Sub-Item 3", CommandCode = 33 });
          DynamicCommands.Add(dropDownCommand);
      }
  
      public void MenuExecute(RibbonCommand command)
      {
          MessageBox.Show(string.Format("You clicked command with ID: {0} (\"{1}\").",
                          command.CommandCode, command.Caption), "Bound Ribbon Control");
      }
  }
  </code></pre>
  
  <p>This code does successfully populate the ribbon with items I added in my DynamicCommands collection, but I would like to support drop-down buttons for items with anything in the SubItems collection (the third button on my example above).</p>
  
  <p>Is there a way to conditionally change the type of control displayed in a DataTemplate. If the object's HasSubItems is true, I would like a BarSubItem placed on the ribbon. If it is false, I will keep the BarButtonItem.</p>