How to create a data bound sub menu

Ribbon for WPF Forum

Posted 7 years ago by David Sherwood
Version: 12.2.0571
Avatar

I'm trying to convert my context menu with a data bound sub menu to ribbon menu. The follow is my current MenuItem

<MenuItem
    DisplayMemberPath="Name"
    Header="Book Grouping"
    ItemsSource="{Binding ShelfGroupingList}"
    Visibility="{Binding IsShelfOptionsSupported,
               Converter={StaticResource BooleanToVisibilityConverter}}">
<MenuItem.ItemContainerStyle>
  <Style TargetType="MenuItem">
    <Setter Property="IsCheckable" Value="True" />
    <Setter Property="IsChecked" Value="{Binding IsChecked}" />
  </Style>
/MenuItem.ItemContainerStyle>
</MenuItem>

 I'm assuming I have to use a PopUpButton. This is my atempt :

<ribbon:PopupButton
  Label="Book Grouping"
  KeyTipAccessText="G"
  Visibility="{Binding IsShelfOptionsSupported,
          Converter={StaticResource BooleanToVisibilityConverter}}">
<ribbon:PopupButton.PopupContent >
   <ribbon:Menu 
      ItemsSource="{Binding ShelfGroupingList}" >
      DisplayMemberPath="Name"
   </ribbon:Menu>
</ribbon:PopupButton.PopupContent>
</ribbon:PopupButton>

 But I can't figure out how to get the ItemContainerStyle where I bind the IsChecked property. This does display the sub menu but it just display the names.

So what do I need to do?  Is it even posible? 

Comments (2)

Answer - Posted 7 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi David,

I believe we've had customers in the past do something along the lines of this:

<ribbon:PopupButton Label="Book Grouping" ...>
 <ribbon:Menu ItemsSource="{Binding ShelfGroupingList}">
  <ribbon:Menu.ItemTemplate>
   <DataTemplate>
    <ribbon:CheckBox Context="MenuItem" Label="{Binding Name}" ... />
   </DataTemplate>
  </ribbon:Menu.ItemTemplate>
 </ribbon:Menu>
</ribbon:PopupButton>


Actipro Software Support

Posted 7 years ago by David Sherwood
Avatar

Thanks! That works fine. I guess I should have thought it myself. Brain freeze!

Thanks for answering.

The latest build of this product (v2019.1 build 0683) was released 19 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.