简体   繁体   English

更改 WPF 应用程序中默认上下文菜单的样式

[英]Change style for the default context menu in WPF Application

I have an WPF desktop application and many text boxes that automatically have the default context menu with Copy\Cut\Paste commands.我有一个 WPF 桌面应用程序和许多文本框,它们自动具有带有Copy\Cut\Paste命令的默认上下文菜单。

Is there any way to change style of this menu, for example add icons or change Foreground color?有没有办法改变这个菜单的风格,例如添加图标或改变前景色?

https://ibb.co/y5LRZnY https://ibb.co/y5LRZnY

You could create a TextBox style with a custom ContextMenu :您可以使用自定义ContextMenu创建TextBox样式:

<Style TargetType="TextBox">
    <Setter Property="ContextMenu">
        <Setter.Value>
            <ContextMenu Foreground="Red">
                <MenuItem Icon="..." Command="Cut"/>
                <MenuItem Icon="..." Command="Copy"/>
                <MenuItem Icon="..." Command="Paste"/>
            </ContextMenu>
        </Setter.Value>
    </Setter>
</Style>

And here is how you would set the Icon property of a MenuItem to an image:下面是如何将MenuItemIcon属性设置为图像:

<MenuItem Command="Paste">
    <MenuItem.Icon>
        <Image Source="pic.png" />
    </MenuItem.Icon>
</MenuItem>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM