This is a migrated thread and some comments may be shown as answers.

RadContextMenu not closing with custom header

2 Answers 102 Views
Menu
This is a migrated thread and some comments may be shown as answers.
Ollie
Top achievements
Rank 1
Ollie asked on 19 Feb 2014, 05:54 PM
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?

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


2 Answers, 1 is accepted

Sort by
0
Rosen Vladimirov
Telerik team
answered on 21 Feb 2014, 01:49 PM
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.

Regards,
Rosen Vladimirov
Telerik
0
Ollie
Top achievements
Rank 1
answered on 27 Feb 2014, 11:10 AM
Thanks for the help, it helped solve the problem
Tags
Menu
Asked by
Ollie
Top achievements
Rank 1
Answers by
Rosen Vladimirov
Telerik team
Ollie
Top achievements
Rank 1
Share this question
or