勾选标记在菜单中显示为黑匣子 [英] Check Mark Showing as a Black Box in Menu

查看:156
本文介绍了勾选标记在菜单中显示为黑匣子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个工具栏中的菜单需要检查,但是当我检查它渲染的项目只是一个黑盒子(我试图上传问题的照片,但StackOverflow不会让我)。当鼠标悬停在复选标记上时,会正确呈现。我不明白我已经尝试删除可能影响它的任何样式,但没有什么似乎影响它。

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.

任何人都可以帮助?

这是菜单项的XAML:

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>


推荐答案

ToolBar 元素为几个控件定义了一些样式,而菜单是其中之一。您可以在 ToolBar.MenuStyleKey 静态属性中找到 Style 键。这种风格是为包含复选标记的面板设置背景#FF212121

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.

不幸的是,我不相信有一种方法可以更改复选标记面板的背景,您将不得不重写那个丑陋的 MenuItem style。

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:


  1. 将上述XAML复制到新的VS解决方案中。

  2. 选择菜单在设计师窗口中。

  3. 右键单击菜单 /编辑模板/编辑副本/ Enter。

  1. Copy the above XAML in a new VS solution.
  2. Select the Menu in the designer window.
  3. Right click on the Menu/ Edit Template / Edit a copy / Enter.

这篇关于勾选标记在菜单中显示为黑匣子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆