Using ItemsSource and DataTemplate

2 posts, 1 answers
  1. Rayne
    Rayne avatar
    241 posts
    Member since:
    Sep 2010

    Posted 02 Aug 2011 Link to this post

    I have a drop down button that contains a context menu as the drop down content. I'm binding my ItemsSource of the ContextMenu to a collection of Items on my view model. Because it's inside a DropDownButton, I'm handling the ItemClick event to close the drop down. But I'd like to also use a command on my view model and pass the bound object as the parameter.
    Right now, I'm using a DataTemplate, but then I get a menuItem inside a menuItem.
    Here is my button and context menu code.
    <telerik:RadDropDownButton Content="Assign" DockPanel.Dock="Right" Margin="3" Name="RolesMenu">
          <telerik:RadContextMenu ItemsSource="{Binding RolesList}" ItemClick="RolesMenu_ItemClick">
                    <telerik:RadMenuItem Header="{Binding RoleName}" Command="{Binding AssignRole}" CommandParameter="{Binding DataContext, RelativeSource={RelativeSource Mode=Self}}" />

    How can I do the same thing as above without getting a menuItem inside a MenuItem?
  2. Answer
    Konstantina avatar
    2332 posts

    Posted 05 Aug 2011 Link to this post

    Hello Rayne,

    In order the ContextMenu to work property you need to attach it like this:


    As explained in this help article. Otherwise it won't work correctly.
    In order to achieve your goal you can use the ItemContainerStyle and through the Setter of the style to set the properties you need.
    Attached I am sending you a sample project in which this is illustrated.

    Hope this helps.

    All the best,
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

  3. DevCraft banner
Back to Top