RadContextMenu not closing with custom header

3 posts, 0 answers
  1. Ollie
    Ollie avatar
    19 posts
    Member since:
    Jun 2012

    Posted 19 Feb 2014 Link to this post

    I have the following XAML for a context menu which has a DataTemplate to show custom menu content using a ContentPresenter, but it does not close when the content in the ContentPresenter is clicked, it only closes when I click on content outside of the ContentPresenter.

    Why is this happening?

    Also, why doesn't the ContentPresenter fill the available MenuItem header, even with 'Stretch' for both the horizontal & vertical alignment is does not fill the available space?

        <telerik:RadContextMenu x:Name="radContextMenu" Placement="Bottom"
                        Visibility="{Binding Path=HasContextMenu, Mode=OneWay, Converter={StaticResource BooleanToVisibilityConverter}}"
                        ItemsSource="{Binding Path=ContextMenu, Mode=OneWay}">
                <DataTemplate DataType="{x:Type vm:MenuCustomViewModel}">
                    <telerik:RadMenuItem x:Name="CustomMenuItem"
                                    Command="{Binding Path=Command, Mode=OneWay}">
                            <ContentPresenter x:Name="MenuContentPresenter"
                                        Content="{Binding Path=Content, Mode=OneWay}">
                <DataTemplate DataType="{x:Type vm:MenuSeparatorViewModel}">
                    <Separator />

  2. Rosen Vladimirov
    Rosen Vladimirov avatar
    640 posts

    Posted 21 Feb 2014 Link to this post

    Hi Ollie,

    Thank you for contacting us.

    When you use DataTemplate for your menu items, they are always wrapped inside RadMenuItem container. So in your case your RadMenuItem from the DataTemplate is wrapped in another RadMenuItem. And when you click on the inner one, RadContextMenu cannot understand that one of its items has been clicked.
    In your scenario I recommend you to use ItemContainerStyle of RadContextMenu and bind Header and HeaderTemplate (if necessary) properties. If you want to have different styles based on the menu item type, you can use ItemContainerStyleSelector. I've prepared a sample project to demonstrate its usage. Please give it a try and inform us in case you have any problems or concerns.

    Also you can check this article which demonstrates how to use ItemContainerStyle. Hope this helps.

    Rosen Vladimirov
  3. DevCraft R3 2016 release webinar banner
  4. Ollie
    Ollie avatar
    19 posts
    Member since:
    Jun 2012

    Posted 27 Feb 2014 in reply to Rosen Vladimirov Link to this post

    Thanks for the help, it helped solve the problem
Back to Top