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

ItemContainerItemContainerStyle Property Breaks RadContextMenu

3 Answers 208 Views
ContextMenu
This is a migrated thread and some comments may be shown as answers.
Scott
Top achievements
Rank 1
Scott asked on 22 Mar 2017, 04:03 PM

I am trying to bind a RadContextMenu to dynamic data. For now though I am simply creating three items in the initialization method.

When I run the code WITHOUT having set the ItemContainerStyle in the RadContextMenu, I get a ContextMenu, however the text being displayed is the class name of the item being bound (see attached file for example)

When I insert the ItemContainerStyle in the XAML, nothing is displayed. However, in the "Opened" event of the RadContextMenu, I do see that the menu is "trying" to open yet nothing is ever displayed.

Without ItemContainerStyle, I get a pop-up with the class name of the items.

With ItemContainerStyle, I get nothing.

Here is the code wireup:

XAML in the UserControl where the RadContextMenu is defined:

<telerik:RadContextMenu.ContextMenu>
    <telerik:RadContextMenu x:Name="WorkListContextMenu"
                            ItemsSource="{Binding WorkListContextMenuItems}"
                            Opened="WorkListContextMenu_Opened">
 
        <telerik:RadContextMenu.ItemContainerStyle>
            <Style TargetType="telerik:RadMenuItem">
                <Setter Property="Header" Value="{Binding Header}" />
                <Setter Property="ItemsSource" Value="{Binding SubItems}" />
                <Setter Property="IsEnabled" Value="{Binding IsEnabled}"/>
                <Setter Property="IsChecked" Value="{Binding IsChecked}"/>
            </Style>
        </telerik:RadContextMenu.ItemContainerStyle>
 
    </telerik:RadContextMenu>
</telerik:RadContextMenu.ContextMenu>

 

When I comment out the "telerik:RadContextMenu.ItemContainerStyle" section, the pop-up appears, but with the classname of the ItemsSource Binding objects.

Not sure what I can do, I've researched for two days now and cannot find the solution. Can someone please offer a suggestion as to what I'm doing wrong?

 

3 Answers, 1 is accepted

Sort by
0
Kalin
Telerik team
answered on 23 Mar 2017, 08:54 AM
Hello Scott,

I assume you are using Implicit Styles - in this case you would need to base the custom Style to default RadMenuItem Style. Try the following and let me know if it helps:


<telerik:RadContextMenu.ItemContainerStyle>
    <Style TargetType="telerik:RadMenuItem" BasedOn="{StaticResource RadMenuItemStyle}">
        <Setter Property="Header" Value="{Binding Header}" />
        <Setter Property="ItemsSource" Value="{Binding SubItems}" />
        <Setter Property="IsEnabled" Value="{Binding IsEnabled}"/>
        <Setter Property="IsChecked" Value="{Binding IsChecked}"/>
    </Style>
</telerik:RadContextMenu.ItemContainerStyle>

Hope this will solve the issue. If not - I would like to ask you to open up a support ticket and attach a sample project reproducing the scenario.

Regards,
Kalin
Telerik by Progress
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
0
Scott
Top achievements
Rank 1
answered on 23 Mar 2017, 12:43 PM

The BasedOn="{StaticResource RadMenuItemStyle}" absolutely fixed this. I had opened a ticket but now have marked it as resolved.

Thank you for getting this information to me. I would like to point out that hours of research on this, including Telerik's own documentation NEVER revealed this attribute is necessary.

0
Kalin
Telerik team
answered on 24 Mar 2017, 08:12 AM
Hi Scott,

I'm glad this solved the issue. For more details regarding Implicit Styles and applying custom styles, please check the following articles from our help documentation:
http://docs.telerik.com/devtools/wpf/styling-and-appearance/styling-apperance-setting-a-theme-overview
http://docs.telerik.com/devtools/wpf/styling-and-appearance/styling-apperance-styling-the-controls

If you have any other questions or concerns, please let us know.

Regards,
Kalin
Telerik by Progress
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
Tags
ContextMenu
Asked by
Scott
Top achievements
Rank 1
Answers by
Kalin
Telerik team
Scott
Top achievements
Rank 1
Share this question
or