3

I am hoping to find a way to remove the space on the left in popup (sub) 'MenuItem's and only have them take up the space required without having to make a whole new template for the control. Is there any sort of dependency property or something of that nature that I could use in this situation? I've tried creating new templates and for what I'm trying to accomplish it's cumbersome and really seems like overkill.

If anybody has any suggestions (especially on how to get rid of that pesky box on the left of the 'MenuItem' without making a new template) please let me know. Any help would be appreciated.

Jason D
  • 2,634
  • 6
  • 33
  • 67
  • Well, I've found myself in a tough situation. Both proposed answers do indeed get the job done but I can only accept one... This is difficult for me since Tim's answer still requires the use of a modified template but in the long run will allow for more flexibility, while Nitesh's answer actually addresses the question exactly as it was asked but in a less elegant and malleable way. – Jason D Jul 18 '13 at 13:26
  • This one is really tough for me, but since Nitesh's answer completely followed the criteria of the question (no custom template involved), I'll accept his answer. Tim, your answer was very helpful as well and I'll gladly upvote it. It's a shame I can't accept both. I would like to thank both of you for your help, though. – Jason D Jul 18 '13 at 13:26
  • No big deal. Just hope you got something you can use from the two answers. – Tim Jul 18 '13 at 13:38
  • Glad it helped. Yes Tim's answer is more flexible, that is why I said there is a trick solution. :) – Nitesh Jul 18 '13 at 13:51

2 Answers2

1

Don't think you can do it without retemplating it. Here's another question that asked for the icon area to be removed but also asked for more. They had to re-template it and the answer includes the template they used, so that might ease your process.

Here's another answer from MSDN forums that I think just removes the icon area.

Not ideal, but there's no "ShowIconArea" property or anything.

Community
  • 1
  • 1
Tim
  • 14,999
  • 1
  • 45
  • 68
1

There is a trick. See if it solve your purpose Set ItemsPanel in a Style and add it in your resource

<Style TargetType="{x:Type MenuItem}">
    <Setter Property="ItemsPanel">
        <Setter.Value>
            <ItemsPanelTemplate>
                <StackPanel Margin="-20,0,0,0" Background="Gray"></StackPanel>
            </ItemsPanelTemplate>
        </Setter.Value>
    </Setter>
</Style>


<Menu>
    <MenuItem Header="MI1">                
        <MenuItem Header="MI1"></MenuItem>
        <MenuItem Header="MI2"></MenuItem>
    </MenuItem>
    <MenuItem Header="MI2"></MenuItem>
</Menu>
Nitesh
  • 7,261
  • 3
  • 30
  • 25