WPF 透明菜单
- 作者: 嗫?暁雲?
- 来源: 51数据库
- 2022-10-20
问题描述
我目前有以下菜单:
<Menu Grid.Row="1" Margin="3" Background="Transparent">
<MenuItem Name="mnuFile" Header="File" Background="#28FFAE04" Foreground="#FFFED528">
<MenuItem Name="mnuSettings" Header="Settings" Background="#28FFAE04" Foreground="#FFFED528" />
<MenuItem Name="mnuExit" Header="Exit" Background="#28FFAE04" Foreground="#FFFED528" />
</MenuItem>
<MenuItem Name="mnuView" Header="View" Background="#28FFAE04" Foreground="#FFFED528" />
<MenuItem Name="mnuAbout" Header="About" Background="#28FFAE04" Foreground="#FFFED528" />
</Menu>
我不知道如何使下落的部分变成半透明或完全透明的类似于浮动文本.这样我就可以看到下面的表格了.
I cannot figure out how to make the part that drops down semi-transparent or completely transparent resembling floating text. So that I can see the form underneath.
任何帮助将不胜感激.谢谢!
Any help would be appreciated. Thanks!
推荐答案
为此,您需要更改 MenuItem 模板.实现您想要的最简单的模板更改是这样的:
To do that, you'll need to change your MenuItem template. The simplest template change that achieves what you want is something like this:
<ControlTemplate x:Key="{x:Static MenuItem.TopLevelHeaderTemplateKey}" TargetType="{x:Type MenuItem}">
<Border Name="Border" >
<Grid>
<ContentPresenter
Margin="6,3,6,3"
ContentSource="Header"
RecognizesAccessKey="True" />
<Popup
Name="Popup"
Placement="Bottom"
IsOpen="{TemplateBinding IsSubmenuOpen}"
AllowsTransparency="True"
Focusable="False"
PopupAnimation="Fade">
<Border
Name="SubmenuBorder"
SnapsToDevicePixels="True"
Background="Transparent">
<StackPanel
IsItemsHost="True"
KeyboardNavigation.DirectionalNavigation="Cycle" />
</Border>
</Popup>
</Grid>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsSuspendingPopupAnimation" Value="true">
<Setter TargetName="Popup" Property="PopupAnimation" Value="None"/>
</Trigger>
<Trigger Property="IsHighlighted" Value="true">
<Setter TargetName="Border" Property="Background" Value="#C0C0C0"/>
<Setter TargetName="Border" Property="BorderBrush" Value="Transparent"/>
</Trigger>
<Trigger SourceName="Popup" Property="Popup.AllowsTransparency" Value="True">
<Setter TargetName="SubmenuBorder" Property="CornerRadius" Value="0,0,4,4"/>
<Setter TargetName="SubmenuBorder" Property="Padding" Value="0,0,0,3"/>
</Trigger>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Foreground" Value="#888888"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
要进行更多自定义,我建议使用 Blend 来编辑您的样式/模板或使用 Kaxaml 的简单样式作为您样式的起点.
For more customization, I'd recommend using Blend to edit your styles/templates or using Kaxaml's Simple Styles as a starting point for your styles.
推荐阅读
- C#通过fleck实现wss协议的WebSocket多人Web实时聊天(附源码)
- 团队城市未满足要求:MSBuildTools12.0_x86_Path 存在
- 使用 MSBuild.exe 在发布模式下构建 C# 解决方案
- 当我发布 Web 应用程序时,AfterPublish 脚本不运行
- 构建时 T4 转换的产品仅在下一个构建中使用
- ASP.NET Core Application (.NET Framework) for Windows x64 only error in project.assets.json
- 新的 .csproj 格式 - 如何将整个目录指定为“链接文件"到子目录?
- 如何将条件编译符号(DefineConstants)传递给 msbuild
- MSBuild 支持 Visual Studio 2017 RTM 中的 T4 模板
- NuGet 包还原找不到包,没有源
热点文章
团队城市未满足要求:MSBuildTools12.0_x86_Path 存在
0
使用 MSBuild.exe 在发布模式下构建 C# 解决方案
0
当我发布 Web 应用程序时,AfterPublish 脚本不运行
0
构建时 T4 转换的产品仅在下一个构建中使用
0
ASP.NET Core Application (.NET Framework) for Windows x64 only error in project.assets.json
0
新的 .csproj 格式 - 如何将整个目录指定为“链接文件"到子目录?
0
如何将条件编译符号(DefineConstants)传递给 msbuild
0
MSBuild 支持 Visual Studio 2017 RTM 中的 T4 模板
0
NuGet 包还原找不到包,没有源
0
使用 C# 6.0 功能运行 TFS 构建
0
