问题
I have a menu inside a toolbar that needs to be checkable but when I check the items it renders as just a black box (I tried to upload a photo of the issue but StackOverflow wouldn't let me). When you mouse over the check mark renders correctly. I don't understand it I have tried removing any styles that might be affecting it but nothing seems to affect it.
Can anyone help?
Here is the XAML for the menu item:
<ToolBar ToolBarTray.IsLocked="True" Margin="0" Padding="0" ToolBar.OverflowMode="Never">
<Button Command="com:FormatCommands.LogInCommand">
<Viewbox Width="15">
<Image Source="..\Resources\Login.png"/>
</Viewbox>
</Button>
<Button Command="com:FormatCommands.LogOutCommand">
<Viewbox Width="15">
<Image Source="..\Resources\Logout.png"/>
</Viewbox>
</Button>
<Button Command="com:FormatCommands.GetTodaysRacesCommand">
<Viewbox Width="15">
<Image Source="..\Resources\list.png"/>
</Viewbox>
</Button>
<Menu>
<MenuItem Header="Markets">
<MenuItem IsCheckable="True" Header="British"/>
<MenuItem IsCheckable="True" Header="Irish" />
</MenuItem>
</Menu>
</ToolBar>
回答1:
The ToolBar
element defines some styles for a few controls and the Menu
is one of them. You can find the Style
key defined in the ToolBar.MenuStyleKey
static property. That style is setting the Background
to #FF212121
for the Panel which contains the check mark.
Unfortunately i don't believe that there is a way to change only the background for the check mark's panel, you will have to override that ugly looking MenuItem
style.
Note: to get the style applied in your case follow this steps:
- Copy the above XAML in a new VS solution.
- Select the
Menu
in the designer window. - Right click on the
Menu
/ Edit Template / Edit a copy / Enter.
来源:https://stackoverflow.com/questions/20643480/check-mark-showing-as-a-black-box-in-menu