Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1096317
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T00:15:58+00:00 2026-05-17T00:15:58+00:00

If I have a Menu defined like this: <Menu> <MenuItem Header=Stuff /> </Menu> When

  • 0

If I have a Menu defined like this:

<Menu>
<MenuItem Header="Stuff" />
</Menu>

When this gets rendered, the ContentPresenter inside of the MenuItem ends up with content like this:

<TextBlock Text="{Binding}" />

which means that it inherits the default styling of TextBlock, which isn’t always desirable.

I know that I can change my MenuItem to be something like:

<MenuItem>
<MenuItem.Header>
<TextBlock Text="Stuff" Style="{DynamiResource MyStyle}" />
</MenuItem.Header>
</MenuItem>

but that would be an annoying requirement.

I know that I can override the default style of MenuItem to explicitely set the ContentTemplate, but that would mean that if the content was something other than a String, or if the specific instance of the MenuItem specified a ContentTemplate, my default style would override that – which would be bad.

I know that somewhere in the magic of WPF, there is a converter or something that is taking the content of type String and creating a DataTemplate that uses a TextBlock, but I can’t find where this is. I figure that there has got to be some way to intercept that magic, but since I can’t locate where the magic happens, I can’t figure out how to intercept it.

Any ideas?

David Mullin

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T00:15:58+00:00Added an answer on May 17, 2026 at 12:15 am

    You could make a DataTemplateSelector returning your custom template for strings but just returning the default for all other types.

    public class MenuStringDataTemplateSelector : DataTemplateSelector
    {
        public override DataTemplate
            SelectTemplate(object item, DependencyObject container)
        {
            if(item is string)
               //TODO return your template
            return base.SelectTemplate(item, container);               
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a collapsible menu item that is defined in XML like this: <item
I've defined a custom content type - news. I also have a menu item
I have a menu which is defined like that: Ext.define('MyApp.FileBrowserContextMenu', { extend: 'Ext.menu.Menu', initComponent:
If I have defined JMenu and JMenuBar like this: private JMenuBar jMenuBar; private JMenu
I have defined a datagrid like this :: <cc:PEDataGrid AutoGenerateColumns=False ItemsSource={Binding Rows} Width=Auto PreviewMouseRightButtonDown=PEGrid_PreviewMouseRightButtonDown
I have an image that has a nested context menu defined in the XAML
I have a header menu and try to define different CSS classes for each
I have the following defined: public class Menu { [DisplayName(Control)] public int Control {
I have a menu generated in php this way. <?php while($rowMenu = mysql_fetch_array($rsMenu)){ $link=category.php?cat=.$rowMenu['MenuItemID'];
I have some actions defined like action = '[module]/[action]' & submit. The result is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.