Whenever I attach a DataTemplate to a MenuItem, each generated menu item gets an extra space on the left side. This extra space looks as wide as the space reserved for the check, which I use. Building a menu manually without a DataTemplate doesn't add this extra space. As an extra wrinkle, if I click on this extra space the menu item goes away but no click event is generated. I don't know why it's adding this extra space. Any ideas?
my xaml code couldn't be more simpler:
Menu with the described extra spaces:
<Menu>
<MenuItem Header="Enemies" ItemsSource="{Binding AvailableEnemyClasses}">
<MenuItem.ItemTemplate>
<DataTemplate>
<MenuItem Header="{Binding}">
</MenuItem>
</DataTemplate>
</MenuItem.ItemTemplate>
</MenuItem>
</Menu>
Menu without extra spaces:
<Menu>
<MenuItem Header="Utilities" >
<MenuItem Header="Enemy01"/>
<MenuItem Header="Enemy02"/>
<MenuItem Header="Enemy03"/>
</MenuItem>
</Menu>
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…