This question is locked. New answers and comments are not allowed.
There seems to be some problems with setting implicit styles on the RadMenuItem control. No matter what I try, implicit styles, explicit styles etc., nothing seems to "take". If I hard code the Style directly on the _content_ (in this case a TextBlock) of the RadMenuItem Header, it works, but in my opinion this is too much work. We use the context menus heavily in our app and if I want this to work I need to copy/paste the style reference well over a thousand times. Shouldn't it be possible to set implicit styles globally for the RadMenuItem and its Header content?
I put together some examples just to try out the various options and see if I could get it to work, but no luck so far. The way I see it, all of the menu examples below should work, but only the last one does, where I am setting a style directly on the hard coded TextBlock in the RadMenuItem Header. The example consists of several identical RadContextMenus, each of them built a little differently. The idea is to get the menus in Comic Sans MS at 15pt. But like I said, only the last of the examples work.
I put together some examples just to try out the various options and see if I could get it to work, but no luck so far. The way I see it, all of the menu examples below should work, but only the last one does, where I am setting a style directly on the hard coded TextBlock in the RadMenuItem Header. The example consists of several identical RadContextMenus, each of them built a little differently. The idea is to get the menus in Comic Sans MS at 15pt. But like I said, only the last of the examples work.
<
UserControl
x:Class
=
"SilverlightApplication3.MainPage"
xmlns:telerik
=
"http://schemas.telerik.com/2008/xaml/presentation"
mc:Ignorable
=
"d"
d:DesignHeight
=
"300"
d:DesignWidth
=
"400"
>
<
UserControl.Resources
>
<!--RadMenuItemStyle-->
<
Style
x:Key
=
"RadMenuItemStyle"
TargetType
=
"telerik:RadMenuItem"
>
<
Setter
Property
=
"FontFamily"
Value
=
"Comic Sans MS"
></
Setter
>
</
Style
>
<!--Implicit style for RadMenuItem-->
<
Style
TargetType
=
"telerik:RadMenuItem"
BasedOn
=
"{StaticResource RadMenuItemStyle}"
>
</
Style
>
<!--Implicit style for RadContextMenu. Seems to have no effect.-->
<
Style
TargetType
=
"telerik:RadContextMenu"
>
<
Setter
Property
=
"FontFamily"
Value
=
"Comic Sans MS"
></
Setter
>
</
Style
>
<!--TextBlockStyle-->
<
Style
x:Key
=
"TextBlockStyle"
TargetType
=
"TextBlock"
>
<
Setter
Property
=
"FontFamily"
Value
=
"Comic Sans MS"
></
Setter
>
<
Setter
Property
=
"FontSize"
Value
=
"16"
></
Setter
>
</
Style
>
<!--Implicit style for TextBlock-->
<
Style
TargetType
=
"TextBlock"
BasedOn
=
"{StaticResource TextBlockStyle}"
>
</
Style
>
<!--Implicit style for HyperlinkButton-->
<
Style
TargetType
=
"HyperlinkButton"
>
<
Setter
Property
=
"FontFamily"
Value
=
"Comic Sans MS"
></
Setter
>
<
Setter
Property
=
"FontSize"
Value
=
"16"
></
Setter
>
</
Style
>
</
UserControl.Resources
>
<
Grid
x:Name
=
"LayoutRoot"
Background
=
"White"
>
<
ScrollViewer
telerik:StyleManager.Theme
=
"Metro"
>
<
StackPanel
>
<
TextBlock
Text
=
"This is only to test that the implicit TextBlock style works on its own. "
Margin
=
"20"
></
TextBlock
>
<
HyperlinkButton
Content
=
"Bound Menu"
HorizontalAlignment
=
"Left"
VerticalAlignment
=
"Top"
Margin
=
"20"
>
<
telerik:RadContextMenu.ContextMenu
>
<
telerik:RadContextMenu
EventName
=
"Click"
telerik:StyleManager.Theme
=
"Metro"
Placement
=
"Bottom"
ItemsSource
=
"{Binding MenuItems}"
>
<
telerik:RadContextMenu.ItemTemplate
>
<
telerik:HierarchicalDataTemplate
>
<!--The implicit TextBlock style should be automatically applied here, but it is not. -->
<
TextBlock
Text
=
"{Binding}"
></
TextBlock
>
</
telerik:HierarchicalDataTemplate
>
</
telerik:RadContextMenu.ItemTemplate
>
</
telerik:RadContextMenu
>
</
telerik:RadContextMenu.ContextMenu
>
</
HyperlinkButton
>
<
HyperlinkButton
Content
=
"Hard coded menu with string headers"
HorizontalAlignment
=
"Left"
VerticalAlignment
=
"Top"
Margin
=
"20"
>
<
telerik:RadContextMenu.ContextMenu
>
<
telerik:RadContextMenu
EventName
=
"Click"
telerik:StyleManager.Theme
=
"Metro"
Placement
=
"Bottom"
>
<
telerik:RadContextMenu.Items
>
<!--The implicit RadMenuItem style should be active here -->
<
telerik:RadMenuItem
Header
=
"Item 1"
></
telerik:RadMenuItem
>
<
telerik:RadMenuItem
Header
=
"Item 2"
></
telerik:RadMenuItem
>
<
telerik:RadMenuItem
Header
=
"Item 3"
></
telerik:RadMenuItem
>
</
telerik:RadContextMenu.Items
>
</
telerik:RadContextMenu
>
</
telerik:RadContextMenu.ContextMenu
>
</
HyperlinkButton
>
<
HyperlinkButton
Content
=
"Hard coded menu, string headers, explicitly set style on RadMenuItem"
HorizontalAlignment
=
"Left"
VerticalAlignment
=
"Top"
Margin
=
"20"
>
<
telerik:RadContextMenu.ContextMenu
>
<
telerik:RadContextMenu
EventName
=
"Click"
telerik:StyleManager.Theme
=
"Metro"
Placement
=
"Bottom"
>
<
telerik:RadContextMenu.Items
>
<!--Even if I set the style explicitly on the RadMenuItem it still does not work. -->
<
telerik:RadMenuItem
Header
=
"Item 1"
Style
=
"{StaticResource RadMenuItemStyle}"
></
telerik:RadMenuItem
>
<
telerik:RadMenuItem
Header
=
"Item 2"
Style
=
"{StaticResource RadMenuItemStyle}"
></
telerik:RadMenuItem
>
<
telerik:RadMenuItem
Header
=
"Item 3"
Style
=
"{StaticResource RadMenuItemStyle}"
></
telerik:RadMenuItem
>
</
telerik:RadContextMenu.Items
>
</
telerik:RadContextMenu
>
</
telerik:RadContextMenu.ContextMenu
>
</
HyperlinkButton
>
<
HyperlinkButton
Content
=
"Hard coded menu with TextBlock headers"
HorizontalAlignment
=
"Left"
VerticalAlignment
=
"Top"
Margin
=
"20"
>
<
telerik:RadContextMenu.ContextMenu
>
<
telerik:RadContextMenu
EventName
=
"Click"
telerik:StyleManager.Theme
=
"Metro"
Placement
=
"Bottom"
>
<
telerik:RadContextMenu.Items
>
<!--Both implicit styles should be active (for TextBlock and RadMenuItem), but still no Comic Sans. -->
<
telerik:RadMenuItem
Style
=
"{StaticResource RadMenuItemStyle}"
>
<
telerik:RadMenuItem.Header
>
<
TextBlock
Text
=
"Item 1"
></
TextBlock
>
</
telerik:RadMenuItem.Header
>
</
telerik:RadMenuItem
>
<
telerik:RadMenuItem
Style
=
"{StaticResource RadMenuItemStyle}"
>
<
telerik:RadMenuItem.Header
>
<
TextBlock
Text
=
"Item 2"
></
TextBlock
>
</
telerik:RadMenuItem.Header
>
</
telerik:RadMenuItem
>
<
telerik:RadMenuItem
Style
=
"{StaticResource RadMenuItemStyle}"
>
<
telerik:RadMenuItem.Header
>
<
TextBlock
Text
=
"Item 3"
></
TextBlock
>
</
telerik:RadMenuItem.Header
>
</
telerik:RadMenuItem
>
</
telerik:RadContextMenu.Items
>
</
telerik:RadContextMenu
>
</
telerik:RadContextMenu.ContextMenu
>
</
HyperlinkButton
>
<
HyperlinkButton
Content
=
"Bound menu with style on TextBlock in data template (this is the only one where Comic Sans MS is correctly applied.)"
HorizontalAlignment
=
"Left"
VerticalAlignment
=
"Top"
Margin
=
"20"
>
<
telerik:RadContextMenu.ContextMenu
>
<
telerik:RadContextMenu
EventName
=
"Click"
telerik:StyleManager.Theme
=
"Metro"
Placement
=
"Bottom"
ItemsSource
=
"{Binding MenuItems}"
>
<
telerik:RadContextMenu.ItemTemplate
>
<
telerik:HierarchicalDataTemplate
>
<!--Finally. When setting the style explicitly on TextBlock things work as expected. -->
<
TextBlock
Text
=
"{Binding}"
Style
=
"{StaticResource TextBlockStyle}"
></
TextBlock
>
</
telerik:HierarchicalDataTemplate
>
</
telerik:RadContextMenu.ItemTemplate
>
</
telerik:RadContextMenu
>
</
telerik:RadContextMenu.ContextMenu
>
</
HyperlinkButton
>
</
StackPanel
>
</
ScrollViewer
>
</
Grid
>
</
UserControl
>